18005: Exposes the bug by simulating a keep-balance run a making a new version.
[arvados.git] / services / api / test / unit / update_priority_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6 require 'update_priority'
7
8 class UpdatePriorityTest < ActiveSupport::TestCase
9   test 'priority 0 but should be >0' do
10     uuid = containers(:running).uuid
11     ActiveRecord::Base.connection.exec_query('UPDATE containers SET priority=0 WHERE uuid=$1', 'test-setup', [[nil, uuid]])
12     assert_equal 0, Container.find_by_uuid(uuid).priority
13     UpdatePriority.update_priority(nolock: true)
14     assert_operator 0, :<, Container.find_by_uuid(uuid).priority
15
16     uuid = containers(:queued).uuid
17     ActiveRecord::Base.connection.exec_query('UPDATE containers SET priority=0 WHERE uuid=$1', 'test-setup', [[nil, uuid]])
18     assert_equal 0, Container.find_by_uuid(uuid).priority
19     UpdatePriority.update_priority(nolock: true)
20     assert_operator 0, :<, Container.find_by_uuid(uuid).priority
21   end
22
23   test 'priority>0 but should be 0' do
24     uuid = containers(:running).uuid
25     ActiveRecord::Base.connection.exec_query('DELETE FROM container_requests WHERE container_uuid=$1', 'test-setup', [[nil, uuid]])
26     assert_operator 0, :<, Container.find_by_uuid(uuid).priority
27     UpdatePriority.update_priority(nolock: true)
28     assert_equal 0, Container.find_by_uuid(uuid).priority
29   end
30 end