@@ -4,6 +4,95 @@ module Concurrent
4
4
5
5
describe CyclicBarrier do
6
6
7
+ let ( :parties ) { 3 }
8
+ let! ( :barrier ) { described_class . new ( 3 ) }
9
+
10
+ context '#initialize' do
11
+
12
+ it 'raises an exception if the initial count is less than 1' do
13
+ expect {
14
+ described_class . new ( 0 )
15
+ } . to raise_error ( ArgumentError )
16
+ end
17
+
18
+ it 'raises an exception if the initial count is not an integer' do
19
+ expect {
20
+ described_class . new ( 'foo' )
21
+ } . to raise_error ( ArgumentError )
22
+ end
23
+ end
24
+
25
+ describe '#parties' do
26
+
27
+ it 'should be the value passed to the constructor' do
28
+ barrier . parties . should eq 3
29
+ end
30
+
31
+ end
32
+
33
+ describe '#number_waiting' do
34
+ context 'without any waiting thread' do
35
+ it 'should be equal to zero' do
36
+ barrier . number_waiting . should eq 0
37
+ end
38
+ end
39
+
40
+ context 'with waiting threads' do
41
+ it 'should be equal to the waiting threads count' do
42
+ Thread . new { barrier . wait }
43
+ Thread . new { barrier . wait }
44
+
45
+ sleep ( 0.1 )
46
+
47
+ barrier . number_waiting . should eq 2
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#broken?' do
53
+ it 'should not be broken when created'
54
+ it 'should not be broken when reset is called without waiting thread'
55
+ it 'should be broken when at least one thread timed out'
56
+ it 'should be restored when reset is called'
57
+ end
58
+
59
+ describe 'reset' do
60
+ it 'should release all waiting threads'
61
+ it 'should not execute the block'
62
+ end
63
+
64
+ describe '#wait' do
65
+ context 'without timeout' do
66
+ it 'should block the thread' do
67
+ t = Thread . new { barrier . wait }
68
+ sleep ( 0.1 )
69
+
70
+ t . status . should eq 'sleep'
71
+ end
72
+
73
+ it 'should release all threads when their number matches the desired one' do
74
+ latch = CountDownLatch . new ( parties )
75
+
76
+ parties . times { Thread . new { barrier . wait ; latch . count_down } }
77
+ latch . wait ( 0.2 ) . should be_true
78
+ barrier . number_waiting . should eq 0
79
+ end
80
+
81
+ it 'executes the block'
82
+ end
83
+
84
+ context 'with timeout' do
85
+ it 'should block the thread'
86
+ it 'should release all threads when their number matches the desired one'
87
+ it 'can return early and break the barrier'
88
+ it 'does not execute the block on timeout'
89
+ end
90
+ end
91
+
92
+ context 'spurious wakeups' do
93
+ it 'should resist'
94
+ end
95
+
7
96
end
8
97
9
98
0 commit comments