aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-10-30 10:30:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-10-30 10:30:21 -0700
commitcb848c8dd716b0243e41a94c9b52c803a3056eb4 (patch)
tree38c865d0af0fb063d9cef158c83bc41bd64fc40a /activerecord
parent61205422bad5f57111d7e9dc4cfb252908878b95 (diff)
downloadrails-cb848c8dd716b0243e41a94c9b52c803a3056eb4.tar.gz
rails-cb848c8dd716b0243e41a94c9b52c803a3056eb4.tar.bz2
rails-cb848c8dd716b0243e41a94c9b52c803a3056eb4.zip
don't sleep in tests
we should be using a countdown latch instead of rolling our own busy-loop.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/migration_test.rb16
1 files 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