X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cac5db66cba0d5dd97c8434853bcbf2ab19fbda5..be66896514a5dccf6364a414d44391a3015592c5:/services/api/test/unit/crunch_dispatch_test.rb diff --git a/services/api/test/unit/crunch_dispatch_test.rb b/services/api/test/unit/crunch_dispatch_test.rb index b7f0a96376..3a8f90a66b 100644 --- a/services/api/test/unit/crunch_dispatch_test.rb +++ b/services/api/test/unit/crunch_dispatch_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' require 'crunch_dispatch' require 'helpers/git_test_helper' @@ -59,7 +63,8 @@ class CrunchDispatchTest < ActiveSupport::TestCase [2, 16384, ['compute2', 'compute1']], [2, 8000, ['compute4', 'compute3']], ].each do |min_nodes, min_ram, expect_nodes| - job = Job.new(runtime_constraints: { + job = Job.new(uuid: 'zzzzz-8i9sb-382lhiizavzhqlp', + runtime_constraints: { 'min_nodes' => min_nodes, 'min_ram_mb_per_node' => min_ram, }) @@ -74,17 +79,6 @@ class CrunchDispatchTest < ActiveSupport::TestCase begin pid = Process.fork do begin - # Abandon database connections inherited from parent - # process. Credit to - # https://github.com/kstephens/rails_is_forked - ActiveRecord::Base.connection_handler.connection_pools.each_value do |pool| - pool.instance_eval do - @reserved_connections = {} - @connections = [] - end - end - ActiveRecord::Base.establish_connection - dispatch = CrunchDispatch.new dispatch.stubs(:did_recently).returns true dispatch.run [] @@ -105,7 +99,7 @@ class CrunchDispatchTest < ActiveSupport::TestCase test 'override --cgroup-root with CRUNCH_CGROUP_ROOT' do ENV['CRUNCH_CGROUP_ROOT'] = '/path/to/cgroup' - Rails.configuration.crunch_job_wrapper = :none + Rails.configuration.Containers.JobsAPI.CrunchJobWrapper = "none" act_as_system_user do j = Job.create(repository: 'active/foo', script: 'hash', @@ -146,7 +140,7 @@ class CrunchDispatchTest < ActiveSupport::TestCase test 'rate limit of partial line segments' do act_as_system_user do - Rails.configuration.crunch_log_partial_line_throttle_period = 1 + Rails.configuration.Containers.Logging.LogPartialLineThrottlePeriod = 1 job = {} job[:bytes_logged] = 0 @@ -201,4 +195,24 @@ class CrunchDispatchTest < ActiveSupport::TestCase assert_equal 5, job[:log_throttle_lines_so_far] end end + + test 'scancel orphaned job nodes' do + Rails.configuration.Containers.JobsAPI.CrunchJobWrapper = "slurm_immediate" + act_as_system_user do + dispatch = CrunchDispatch.new + + squeue_resp = IO.popen("echo zzzzz-8i9sb-pshmckwoma9plh7\necho thisisnotvalidjobuuid\necho zzzzz-8i9sb-4cf0abc123e809j\necho zzzzz-dz642-o04e3r651turtdr\n") + scancel_resp = IO.popen("true") + + IO.expects(:popen). + with(['squeue', '-a', '-h', '-o', '%j']). + returns(squeue_resp) + + IO.expects(:popen). + with(dispatch.sudo_preface + ['scancel', '-n', 'zzzzz-8i9sb-4cf0abc123e809j']). + returns(scancel_resp) + + dispatch.check_orphaned_slurm_jobs + end + end end