FIX: DistributedMutex (#7953)

This commit is contained in:
Daniel Waterworth
2019-08-01 09:12:05 +01:00
committed by GitHub
parent 3b575b82f3
commit 20bc4a38a5
4 changed files with 368 additions and 32 deletions

View File

@ -98,4 +98,47 @@ describe DistributedMutex do
end
end
context "executions" do
it "should not allow critical sections to overlap" do
connections = (0...3).map { DiscourseRedis.new }
scenario =
Concurrency::Scenario.new do |execution|
locked = false
$redis.del('mutex_key')
connections.each do |connection|
connection.unwatch
end
3.times do |i|
execution.spawn do
begin
redis =
Concurrency::RedisWrapper.new(
connections[i],
execution
)
2.times do
DistributedMutex.synchronize('mutex_key', redis: redis) do
raise "already locked #{execution.path}" if locked
locked = true
execution.yield
raise "already unlocked #{execution.path}" unless locked
locked = false
end
end
rescue Redis::ConnectionError
end
end
end
end
scenario.run(runs: 10)
end
end
end