Created
April 12, 2012 00:41
-
-
Save dbenhur/2363790 to your computer and use it in GitHub Desktop.
RSpec #should_recieve can't count correctly with threads
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
require 'rspec' | |
T = 10000 | |
N = 200 | |
class ConcurrentSender | |
def initialize(collaborator,message,threads,sends) | |
@collaborator,@message,@threads,@sends = collaborator,message,threads,sends | |
@tasks = [] | |
end | |
def run | |
@threads.times do | |
@tasks << Thread.new do | |
@sends.times { @collaborator.send @message } | |
end | |
end | |
@tasks.each{|t| t.join } | |
@tasks = [] | |
end | |
end | |
describe "should_recieve expectation counter" do | |
it "should correctly count messages in concurrent execution" do | |
dummy = Object.new | |
dummy.should_receive(:foo).exactly(N*T).times | |
cs = ConcurrentSender.new(dummy,:foo,T,N) | |
cs.run | |
end | |
end |
Author
dbenhur
commented
Apr 12, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment