1 require 'minitest/autorun'
3 class TestCrunchJob < Minitest::Test
11 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
13 script_version: 'master',
14 repository: File.absolute_path('../../../..', __FILE__),
15 script_parameters: {foo: 'bar'},
23 File.absolute_path '../../bin/crunch-job', __FILE__
26 # Return environment suitable for running crunch-job.
29 env['CRUNCH_REFRESH_TRIGGER'] =
30 File.absolute_path('../../../../tmp/crunch-refresh-trigger', __FILE__)
38 # Encode job record to json and run it with crunch-job.
40 # opts[:binstubs] is an array of X where ./binstub_X is added to
41 # PATH in order to mock system programs.
42 def tryjobrecord jobrecord, opts={}
44 (opts[:binstubs] || []).each do |binstub|
45 env['PATH'] = File.absolute_path('../binstub_'+binstub, __FILE__) + ':' + env['PATH']
47 system env, crunchjob, '--job', jobrecord.to_json
51 out, err = capture_subprocess_io do
52 system crunchenv, crunchjob, '--job', '"}{"'
54 assert_equal false, $?.success?
55 # Must not conflict with our special exit statuses
57 assert_match /JSON/, err
60 def test_fail_sanity_check
61 out, err = capture_subprocess_io do
63 tryjobrecord j, binstubs: ['sanity_check']
65 assert_equal 75, $?.exitstatus
66 assert_match /Sanity check failed: 7/, err
69 def test_fail_docker_sanity_check
70 out, err = capture_subprocess_io do
72 j[:docker_image_locator] = '4d449b9d34f2e2222747ef79c53fa3ff+1234'
73 tryjobrecord j, binstubs: ['sanity_check']
75 assert_equal 75, $?.exitstatus
76 assert_match /Sanity check failed: 8/, err
79 def test_no_script_specified
80 out, err = capture_subprocess_io do
81 j = jobspec :grep_local
85 assert_match /No script specified/, err
89 def test_fail_clean_tmp
90 out, err = capture_subprocess_io do
91 j = jobspec :grep_local
92 tryjobrecord j, binstubs: ['clean_fail']
94 assert_match /Failing mount stub was called/, err
95 assert_match /clean work dirs: exit 44\n$/, err
96 assert_equal SPECIAL_EXIT[:EX_RETRY_UNLOCKED], $?.exitstatus
99 def test_output_collection_owner_uuid
100 j = jobspec :grep_local
101 out, err = capture_subprocess_io do
102 tryjobrecord j, binstubs: ['output_coll_owner']
104 assert_match /owner_uuid: #{j['owner_uuid']}/, err
107 def test_docker_image_missing
108 skip 'API bug: it refuses to create this job in Running state'
109 out, err = capture_subprocess_io do
110 j = jobspec :grep_local
111 j[:docker_image_locator] = '4d449b9d34f2e2222747ef79c53fa3ff+1234'
112 tryjobrecord j, binstubs: ['docker_noop']
114 assert_match /No Docker image hash found from locator/, err
118 def test_script_version_not_found_in_repository
119 bogus_version = 'f8b72707c1f5f740dbf1ed56eb429a36e0dee770'
120 out, err = capture_subprocess_io do
121 j = jobspec :grep_local
122 j[:script_version] = bogus_version
125 assert_match /'#{bogus_version}' not found, giving up/, err
129 # Ensure procstatus is not interpreted as a temporary infrastructure
130 # problem. Would be assert_http_4xx if this were http.
131 def assert_jobfail procstatus
132 refute_includes SPECIAL_EXIT.values, procstatus.exitstatus
133 assert_equal false, procstatus.success?