9318: running and finished containers and fixtures updated.
[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   ].each do |type, fixture, label, num_children, state, success, progress|
15     test "children of #{fixture}" do
16       use_token 'active'
17       obj = find_fixture(type, fixture)
18       wu = obj.work_unit(label)
19
20       if label != nil
21         assert_equal(label, wu.label)
22       else
23         assert_equal(obj.name, wu.label)
24       end
25       assert_equal(obj['uuid'], wu.uuid)
26       assert_equal(state, wu.state_label)
27       assert_equal(success, wu.success?)
28       assert_equal(progress, wu.progress)
29
30       assert_equal(num_children, wu.children.size)
31       wu.children.each do |child|
32         assert_equal(true, child.respond_to?(:script))
33       end
34     end
35   end
36
37   [
38     [Job, 'running_job_with_components', 1, 1, nil],
39     [Job, 'queued', nil, nil, 1],
40     [PipelineInstance, 'pipeline_in_running_state', 1, 1, nil],
41     [PipelineInstance, 'has_component_with_completed_jobs', 60, 60, nil],
42   ].each do |type, fixture, walltime, cputime, queuedtime|
43     test "times for #{fixture}" do
44       use_token 'active'
45       obj = find_fixture(type, fixture)
46       wu = obj.work_unit
47
48       if walltime
49         assert_equal true, (wu.walltime >= walltime)
50       else
51         assert_equal walltime, wu.walltime
52       end
53
54       if cputime
55         assert_equal true, (wu.cputime >= cputime)
56       else
57         assert_equal cputime, wu.cputime
58       end
59
60       if queuedtime
61         assert_equal true, (wu.queuedtime >= queuedtime)
62       else
63         assert_equal queuedtime, wu.queuedtime
64       end
65     end
66   end
67
68   [
69     [Job, 'active', 'running_job_with_components', true],
70     [Job, 'active', 'queued', false],
71     [Job, nil, 'completed_job_in_publicly_accessible_project', true],
72     [Job, 'active', 'completed_job_in_publicly_accessible_project', true],
73     [PipelineInstance, 'active', 'pipeline_in_running_state', true],  # no log, but while running the log link points to pi Log tab
74     [PipelineInstance, nil, 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
75     [PipelineInstance, 'active', 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false], #no log for completed pi
76     [Job, nil, 'job_in_publicly_accessible_project_but_other_objects_elsewhere', false, "Log unavailable"],
77   ].each do |type, token, fixture, has_log, log_link|
78     test "link_to_log for #{fixture} for #{token}" do
79       use_token token if token
80       obj = find_fixture(type, fixture)
81       wu = obj.work_unit
82
83       link = "#{wu.uri}#Log" if has_log
84       link_to_log = wu.link_to_log
85
86       if has_log
87         assert_includes link_to_log, link
88       else
89         assert_equal log_link, link_to_log
90       end
91     end
92   end
93 end