Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Protect against stale reads in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgreen committed Feb 9, 2014
1 parent 72b4fba commit 12bfe2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/elevate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class TestController
include Elevate

def initialize
@invocations = {}
@invocations = ThreadsafeProxy.new({})
@counter = 0
@threads = []
@updates = []
Expand Down
18 changes: 18 additions & 0 deletions spec/support/threadsafe_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ThreadsafeProxy
def initialize(target)
@mutex = Mutex.new
@target = target
end

def method_missing(m, *args, &block)
@mutex.synchronize do
@target.__send__(m, *args, &block)
end
end

def respond_to_missing?(m, include_private = false)
@mutex.synchronize do
@target.respond_to_missing?(m, include_private)
end
end
end

0 comments on commit 12bfe2b

Please sign in to comment.