Sha256: 4763e844416d727d91d96a247ec82d0dc0f70d4229733ea4ac78678c996d5bf7
Contents?: true
Size: 1.22 KB
Versions: 323
Compression:
Stored size: 1.22 KB
Contents
require 'spec_helper' def run_in_two_threads(proc1, proc2) t1 = Thread.new &proc1 sleep test_latency # t1 must run before t2 t2 = Thread.new { proc2.call; Thread.kill t1 } t2.join(test_latency * 2) ensure Thread.kill t1 if t1 Thread.kill t2 if t2 end describe Listen::Turnstile do before { @called = false } describe '#wait' do context 'without a signal' do it 'blocks one thread indefinitely' do run_in_two_threads lambda { subject.wait @called = true }, lambda { sleep test_latency } @called.should be_false end end context 'with a signal' do it 'blocks one thread until it recieves a signal from another thread' do run_in_two_threads lambda { subject.wait @called = true }, lambda { subject.signal sleep test_latency } @called.should be_true end end end describe '#signal' do context 'without a wait-call before' do it 'does nothing' do run_in_two_threads lambda { subject.signal @called = true }, lambda { sleep test_latency } @called.should be_true end end end end
Version data entries
323 entries across 224 versions & 13 rubygems