From cb848c8dd716b0243e41a94c9b52c803a3056eb4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 30 Oct 2015 10:30:21 -0700 Subject: don't sleep in tests we should be using a countdown latch instead of rolling our own busy-loop. --- activerecord/test/cases/migration_test.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 9c4fa0df4f..741bec6017 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -606,30 +606,26 @@ class MigrationTest < ActiveRecord::TestCase end def with_another_process_holding_lock(lock_key) - other_process_has_lock = false - test_terminated = false + thread_lock = Concurrent::CountDownLatch.new + test_terminated = Concurrent::CountDownLatch.new other_process = Thread.new do begin conn = ActiveRecord::Base.connection_pool.checkout conn.get_advisory_lock(lock_key) - other_process_has_lock = true - while !test_terminated do # hold the lock open until we tested everything - sleep(0.01) - end + thread_lock.count_down + test_terminated.wait # hold the lock open until we tested everything ensure conn.release_advisory_lock(lock_key) ActiveRecord::Base.connection_pool.checkin(conn) end end - while !other_process_has_lock # wait until the 'other process' has the lock - sleep(0.01) - end + thread_lock.wait # wait until the 'other process' has the lock yield - test_terminated = true + test_terminated.count_down other_process.join end end -- cgit v1.2.3