X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/011f79355a338f43089af498f9980a9488d68927..dabddd30051245241a2ca02c30e8354d68d9eb2b:/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 2bdbf7fb07..900c8e33cb 100644 --- a/services/api/test/unit/crunch_dispatch_test.rb +++ b/services/api/test/unit/crunch_dispatch_test.rb @@ -1,10 +1,16 @@ require 'test_helper' require 'crunch_dispatch' +require 'helpers/git_test_helper' class CrunchDispatchTest < ActiveSupport::TestCase + include GitTestHelper + test 'choose cheaper nodes first' do act_as_system_user do + # Replace test fixtures with a set suitable for testing dispatch Node.destroy_all + + # Idle nodes with different prices [['compute1', 3.20, 32], ['compute2', 1.60, 16], ['compute3', 0.80, 8]].each do |hostname, price, cores| @@ -21,6 +27,7 @@ class CrunchDispatchTest < ActiveSupport::TestCase 'total_scratch_mb' => cores*10000, }) end + # Node with no price information Node.create!(hostname: 'compute4', info: { @@ -31,6 +38,7 @@ class CrunchDispatchTest < ActiveSupport::TestCase 'total_ram_mb' => 8192, 'total_scratch_mb' => 80000, }) + # Cheap but busy node Node.create!(hostname: 'compute5', info: { @@ -76,7 +84,10 @@ class CrunchDispatchTest < ActiveSupport::TestCase end end ActiveRecord::Base.establish_connection - CrunchDispatch.new.run [] + + dispatch = CrunchDispatch.new + dispatch.stubs(:did_recently).returns true + dispatch.run [] ensure Process.exit! end @@ -87,11 +98,35 @@ class CrunchDispatchTest < ActiveSupport::TestCase ensure Process.kill("TERM", pid) end - assert_with_timeout 5, "Dispatch did not unlock #{lockfile}" do + assert_with_timeout 20, "Dispatch did not unlock #{lockfile}" do can_lock(lockfile) end end + test 'override --cgroup-root with CRUNCH_CGROUP_ROOT' do + ENV['CRUNCH_CGROUP_ROOT'] = '/path/to/cgroup' + Rails.configuration.crunch_job_wrapper = :none + act_as_system_user do + j = Job.create(repository: 'active/foo', + script: 'hash', + script_version: '4fe459abe02d9b365932b8f5dc419439ab4e2577', + script_parameters: {}) + ok = false + Open3.expects(:popen3).at_least_once.with do |*args| + if args.index(j.uuid) + ok = ((i = args.index '--cgroup-root') and + (args[i+1] == '/path/to/cgroup')) + end + true + end.raises(StandardError.new('all is well')) + dispatch = CrunchDispatch.new + dispatch.parse_argv ['--jobs'] + dispatch.refresh_todo + dispatch.start_jobs + assert ok + end + end + def assert_with_timeout timeout, message t = 0 while (t += 0.1) < timeout