1 require 'minitest/autorun'
3 class TestCrunchJob < Minitest::Test
12 script_version: 'master',
13 repository: File.absolute_path('../../../..', __FILE__),
14 script_parameters: {foo: 'bar'},
22 File.absolute_path '../../bin/crunch-job', __FILE__
25 # Return environment suitable for running crunch-job.
28 env['PERLLIB'] = File.absolute_path('../../../perl/lib', __FILE__)
36 # Encode job record to json and run it with crunch-job.
38 # opts[:binstubs] is an array of X where ./binstub_X is added to
39 # PATH in order to mock system programs.
40 def tryjobrecord jobrecord, opts={}
42 (opts[:binstubs] || []).each do |binstub|
43 env['PATH'] = File.absolute_path('../binstub_'+binstub, __FILE__) + ':' + env['PATH']
45 system env, crunchjob, '--job', jobrecord.to_json
49 out, err = capture_subprocess_io do
50 system crunchenv, crunchjob, '--job', '"}{"'
52 assert_equal false, $?.success?
53 # Must not conflict with our special exit statuses
55 assert_match /JSON/, err
58 def test_fail_sanity_check
59 out, err = capture_subprocess_io do
61 tryjobrecord j, binstubs: ['sanity_check']
63 assert_equal 75, $?.exitstatus
64 assert_match /Sanity check failed: 7/, err
67 def test_fail_docker_sanity_check
68 out, err = capture_subprocess_io do
70 j[:docker_image_locator] = '4d449b9d34f2e2222747ef79c53fa3ff+1234'
71 tryjobrecord j, binstubs: ['sanity_check']
73 assert_equal 75, $?.exitstatus
74 assert_match /Sanity check failed: 8/, err
77 def test_no_script_specified
78 out, err = capture_subprocess_io do
79 j = jobspec :grep_local
83 assert_match /No script specified/, err
87 def test_fail_clean_tmp
88 out, err = capture_subprocess_io do
89 j = jobspec :grep_local
90 tryjobrecord j, binstubs: ['clean_fail']
92 assert_match /Failing mount stub was called/, err
93 assert_match /Clean work dirs: exit 1\n$/, err
94 assert_equal SPECIAL_EXIT[:EX_RETRY_UNLOCKED], $?.exitstatus
97 def test_docker_image_missing
98 skip 'API bug: it refuses to create this job in Running state'
99 out, err = capture_subprocess_io do
100 j = jobspec :grep_local
101 j[:docker_image_locator] = '4d449b9d34f2e2222747ef79c53fa3ff+1234'
102 tryjobrecord j, binstubs: ['docker_noop']
104 assert_match /No Docker image hash found from locator/, err
108 def test_script_version_not_found_in_repository
109 bogus_version = 'f8b72707c1f5f740dbf1ed56eb429a36e0dee770'
110 out, err = capture_subprocess_io do
111 j = jobspec :grep_local
112 j[:script_version] = bogus_version
115 assert_match /'#{bogus_version}' not found, giving up/, err
119 # Ensure procstatus is not interpreted as a temporary infrastructure
120 # problem. Would be assert_http_4xx if this were http.
121 def assert_jobfail procstatus
122 refute_includes SPECIAL_EXIT.values, procstatus.exitstatus
123 assert_equal false, procstatus.success?