1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class WorkUnitTest < ActiveSupport::TestCase
9 reset_api_fixtures :after_each_test, false
12 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
16 [Job, 'running_job_with_components', "jwu", 2, "Running", nil, 0.5],
17 [PipelineInstance, 'pipeline_in_running_state', nil, 1, "Running", nil, 0.0],
18 [PipelineInstance, 'has_component_with_completed_jobs', nil, 3, "Complete", true, 1.0],
19 [PipelineInstance, 'pipeline_with_tagged_collection_input', "pwu", 1, "Ready", nil, 0.0],
20 [Container, 'requester', 'cwu', 1, "Complete", true, 1.0],
21 [ContainerRequest, 'cr_for_requester', 'cwu', 1, "Complete", true, 1.0],
22 [ContainerRequest, 'queued', 'cwu', 0, "Queued", nil, 0.0], # priority 1
23 [ContainerRequest, 'canceled_with_queued_container', 'cwu', 0, "Cancelled", false, 0.0],
24 [ContainerRequest, 'canceled_with_locked_container', 'cwu', 0, "Queued", nil, 0.0],
25 [ContainerRequest, 'canceled_with_running_container', 'cwu', 1, "Running", nil, 0.0],
26 ].each do |type, fixture, label, num_children, state, success, progress|
27 test "children of #{fixture}" do
29 obj = find_fixture(type, fixture)
30 wu = obj.work_unit(label)
33 assert_equal(label, wu.label)
35 assert_equal(obj.name, wu.label)
37 assert_equal(obj['uuid'], wu.uuid)
38 assert_equal(state, wu.state_label)
39 assert_equal(success, wu.success?)
40 assert_equal(progress, wu.progress)
42 assert_equal(num_children, wu.children.size)
43 wu.children.each do |child|
44 assert_equal(true, child.respond_to?(:script))
50 ['cr_for_failed', 'Failed', 33],
51 ['completed', 'Complete', 0],
52 ].each do |cr_fixture, state, exit_code|
53 test "Completed ContainerRequest state = #{state} with exit_code = #{exit_code}" do
55 obj = find_fixture(ContainerRequest, cr_fixture)
57 assert_equal state, wu.state_label
58 assert_equal exit_code, wu.exit_code
63 [Job, 'running_job_with_components', 1, 1, nil, true],
64 [Job, 'queued', nil, 0, 1, false],
65 [PipelineInstance, 'pipeline_in_running_state', 1, 1, nil, false],
66 [PipelineInstance, 'has_component_with_completed_jobs', 60, 60, nil, true],
67 ].each do |type, fixture, walltime, cputime, queuedtime, cputime_more_than_walltime|
68 test "times for #{fixture}" do
70 obj = find_fixture(type, fixture)
74 assert_equal true, (wu.walltime >= walltime)
76 assert_equal walltime, wu.walltime
80 assert_equal true, (wu.cputime >= cputime)
82 assert_equal cputime, wu.cputime
86 assert_equal true, (wu.queuedtime >= queuedtime)
88 assert_equal queuedtime, wu.queuedtime
91 assert_equal cputime_more_than_walltime, (wu.cputime > wu.walltime) if wu.cputime and wu.walltime
97 assert find_fixture(Job, 'running').work_unit.can_cancel?
98 refute find_fixture(Container, 'running').work_unit.can_cancel?
99 assert find_fixture(ContainerRequest, 'running').work_unit.can_cancel?
101 use_token 'spectator' do
102 refute find_fixture(ContainerRequest, 'running_anonymous_accessible').work_unit.can_cancel?
105 assert find_fixture(ContainerRequest, 'running_anonymous_accessible').work_unit.can_cancel?