Sha256: 80cd7305374ae0d5aa3089031ee1ffda9e735bbeae37a2f815ae44596a134a50
Contents?: true
Size: 1.32 KB
Versions: 7
Compression:
Stored size: 1.32 KB
Contents
require "spec_helper" require "bunny/concurrent/condition" describe Bunny::Concurrent::Condition do describe "#wait" do it "blocks current thread until notified" do condition = described_class.new xs = [] t = Thread.new do xs << :notified sleep 0.25 condition.notify end condition.wait xs.should == [:notified] end end describe "#notify" do it "notifies a single thread waiting on the latch" do condition = described_class.new xs = [] t1 = Thread.new do condition.wait xs << :notified1 end t2 = Thread.new do condition.wait xs << :notified2 end sleep 0.25 condition.notify sleep 0.5 xs.should satisfy { |ys| ys.size == 1 && (ys.include?(:notified1) || ys.include?(:notified2)) } end end describe "#notify_all" do it "notifies all the threads waiting on the latch" do condition = described_class.new @xs = [] t1 = Thread.new do condition.wait @xs << :notified1 end t2 = Thread.new do condition.wait @xs << :notified2 end sleep 0.5 condition.notify_all sleep 0.5 @xs.should include(:notified1) @xs.should include(:notified2) end end end
Version data entries
7 entries across 7 versions & 1 rubygems