Last active
March 4, 2016 18:42
-
-
Save subelsky/8dcc5c4bb10071f5abf0 to your computer and use it in GitHub Desktop.
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 is how I'd use threads in rspec to test whether a shared state primitive works as expected | |
#(pessimistic database lock,advisory database lock, mutex, etc.) | |
around do |example| | |
die = false | |
lock_taker = Thread.new do | |
code_that_takes a lock do | |
loop do | |
break if die | |
sleep 0.1 # not strictly necessary but slows CPU churn | |
end | |
end | |
example.run | |
die = true | |
locker_taker.join | |
end | |
it "can't get an adivsory lock when alreaedy locked" do | |
code_that_also_takes_a_lock_but_fails | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment