-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes the flaky test "ActiveRecord::DebugErrors::DisplayConnectionOwners#execute when ActiveRecord::LockWaitTimeout occurs displays transactions and processlist." I suspect there is more than 1 second time delay between the start time of the two threads, and CyclicBarrier shortens the delay.
- Loading branch information
Showing
3 changed files
with
42 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This class is a simple implementation of CyclicBarrier in Java | ||
class CyclicBarrier | ||
def initialize(parties) | ||
@cv = ConditionVariable.new | ||
@mutex = Mutex.new | ||
@parties = parties | ||
@number_waiting = 0 | ||
end | ||
|
||
def await(timeout = nil) | ||
@mutex.synchronize do | ||
@number_waiting += 1 | ||
if @number_waiting == @parties | ||
@cv.broadcast | ||
else | ||
@cv.wait(@mutex, timeout) | ||
raise Timeout::Error if @number_waiting != @parties | ||
end | ||
end | ||
end | ||
end |