Merge branch '9353-retry-http-error' closes #9353
[arvados.git] / apps / workbench / test / unit / work_unit_test.rb
1 require 'test_helper'
2
3 class WorkUnitTest < ActiveSupport::TestCase
4   setup do
5     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
6   end
7
8   [
9     [Job, 'running_job_with_components', "jwu", 2, "Running", nil, 0.5],
10     [PipelineInstance, 'pipeline_in_running_state', nil, 1, "Running", nil, 0.0],
11     [PipelineInstance, 'has_component_with_completed_jobs', nil, 3, "Complete", true, 1.0],
12     [PipelineInstance, 'pipeline_with_tagged_collection_input', "pwu", 1, "Ready", nil, 0.0],
13     [Container, 'requester', 'cwu', 1, "Complete", true, 1.0],
14     [ContainerRequest, 'cr_for_requester', 'cwu', 1, "Complete", true, 1.0],
15   ].each do |type, fixture, label, num_children, state, success, progress|
16     test "children of #{fixture}" do
17       use_token 'active'
18       obj = find_fixture(type, fixture)
19       wu = obj.work_unit(label)
20
21       if label != nil
22         assert_equal(label, wu.label)
23       else
24         assert_equal(obj.name, wu.label)
25       end
26       assert_equal(obj['uuid'], wu.uuid)
27       assert_equal(state, wu.state_label)
28       assert_equal(success, wu.success?)
29       assert_equal(progress, wu.progress)
30
31       assert_equal(num_children, wu.children.size)
32       wu.children.each do |child|
33         assert_equal(true, child.respond_to?(:script))
34       end
35     end
36   end
37
38   [
39     [Job, 'running_job_with_components', 1, 1, nil],
40     [Job, 'queued', nil, nil, 1],
41     [PipelineInstance, 'pipeline_in_running_state', 1, 1, nil],
42     [PipelineInstance, 'has_component_with_completed_jobs', 60, 60, nil],
43   ].each do |type, fixture, walltime, cputime, queuedtime|
44     test "times for #{fixture}" do
45       use_token 'active'
46       obj = find_fixture(type, fixture)
47       wu = obj.work_unit
48
49       if walltime
50         assert_equal true, (wu.walltime >= walltime)
51       else
52         assert_equal walltime, wu.walltime
53       end
54
55       if cputime
56         assert_equal true, (wu.cputime >= cputime)
57       else
58         assert_equal cputime, wu.cputime
59       end
60
61       if queuedtime
62         assert_equal true, (wu.queuedtime >= queuedtime)
63       else
64         assert_equal queuedtime, wu.queuedtime
65       end
66     end
67   end
68
69   [
70     [Job, 'active', 'running_job_with_components', true],
71     [Job, 'active', 'queued', false],
72     [Job, nil, 'completed_job_in_publicly_accessible_project', true],
73     [Job, 'active', 'completed_job_in_publicly_accessible_project', true],
74     [PipelineInstance, 'active', 'pipeline_in_running_state', true],  # no log, but while running the log link points to pi Log tab
75     [PipelineInstance, nil, 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
76     [PipelineInstance, 'active', 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false], #no log for completed pi
77     [Job, nil, 'job_in_publicly_accessible_project_but_other_objects_elsewhere', false, "Log unavailable"],
78   ].each do |type, token, fixture, has_log, log_link|
79     test "link_to_log for #{fixture} for #{token}" do
80       use_token token if token
81       obj = find_fixture(type, fixture)
82       wu = obj.work_unit
83
84       link = "#{wu.uri}#Log" if has_log
85       link_to_log = wu.link_to_log
86
87       if has_log
88         assert_includes link_to_log, link
89       else
90         assert_equal log_link, link_to_log
91       end
92     end
93   end
94 end