Skip to content

Commit 5b71e7a

Browse files
committed
fixed test race condition
1 parent a3e62b7 commit 5b71e7a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

spec/concurrent/channel/buffered_channel_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Concurrent
55
describe BufferedChannel do
66

77
let(:size) { 2 }
8-
let(:channel) { BufferedChannel.new(size) }
8+
let!(:channel) { BufferedChannel.new(size) }
99
let(:probe) { Probe.new }
1010

1111
context 'without timeout' do

spec/concurrent/channel/unbuffered_channel_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Concurrent
44

55
describe UnbufferedChannel do
66

7-
let(:channel) { subject }
7+
let!(:channel) { subject }
88
let(:probe) { Probe.new }
99

1010
context 'with one thread' do
@@ -37,9 +37,9 @@ module Concurrent
3737
result = nil
3838

3939
Thread.new { channel.push 42 }
40-
Thread.new { result = channel.pop }
40+
Thread.new { result = channel.pop; }
4141

42-
sleep(0.05)
42+
sleep(0.1)
4343

4444
result.should eq 42
4545
end
@@ -51,10 +51,21 @@ module Concurrent
5151
Thread.new { result << channel.pop }
5252
Thread.new { result << channel.pop }
5353

54-
sleep(0.05)
54+
sleep(0.1)
5555

5656
result.should have(1).items
5757
end
58+
59+
it 'gets the pushed value when ready' do
60+
result = nil
61+
62+
Thread.new { result = channel.pop; }
63+
Thread.new { channel.push 57 }
64+
65+
sleep(0.1)
66+
67+
result.should eq 57
68+
end
5869
end
5970

6071
describe 'select' do

0 commit comments

Comments
 (0)