|
12 | 12 |
|
13 | 13 | context '#post' do
|
14 | 14 |
|
15 |
| - it 'raises an exception if no block is given' do |
16 |
| - lambda { |
17 |
| - subject.post |
18 |
| - }.should raise_error(ArgumentError) |
19 |
| - end |
20 |
| - |
21 |
| - it 'returns true when the block is added to the queue' do |
22 |
| - subject.post{ nil }.should be_true |
23 |
| - end |
24 |
| - |
25 |
| - it 'calls the block with the given arguments' do |
26 |
| - @expected = nil |
27 |
| - subject.post(1, 2, 3) do |a, b, c| |
28 |
| - @expected = a + b + c |
29 |
| - end |
30 |
| - sleep(0.1) |
31 |
| - @expected.should eq 6 |
32 |
| - end |
33 |
| - |
34 | 15 | it 'rejects the block while shutting down' do
|
| 16 | + latch = Concurrent::CountDownLatch.new(1) |
35 | 17 | subject.post{ sleep(1) }
|
36 | 18 | subject.shutdown
|
37 |
| - @expected = nil |
38 |
| - subject.post(1, 2, 3) do |a, b, c| |
39 |
| - @expected = a + b + c |
40 |
| - end |
41 |
| - @expected.should be_nil |
| 19 | + subject.post{ latch.count_down } |
| 20 | + latch.wait(0.1).should be_false |
42 | 21 | end
|
43 | 22 |
|
44 | 23 | it 'returns false while shutting down' do
|
|
49 | 28 |
|
50 | 29 | it 'rejects the block once shutdown' do
|
51 | 30 | subject.shutdown
|
52 |
| - @expected = nil |
53 |
| - subject.post(1, 2, 3) do |a, b, c| |
54 |
| - @expected = a + b + c |
55 |
| - end |
56 |
| - @expected.should be_nil |
| 31 | + latch = Concurrent::CountDownLatch.new(1) |
| 32 | + subject.post{ sleep(1) } |
| 33 | + subject.post{ latch.count_down } |
| 34 | + latch.wait(0.1).should be_false |
57 | 35 | end
|
58 | 36 |
|
59 | 37 | it 'returns false once shutdown' do
|
|
62 | 40 | sleep(0.1)
|
63 | 41 | subject.post{ nil }.should be_false
|
64 | 42 | end
|
65 |
| - |
66 |
| - it 'aliases #<<' do |
67 |
| - @expected = false |
68 |
| - subject << proc { @expected = true } |
69 |
| - sleep(0.1) |
70 |
| - @expected.should be_true |
71 |
| - end |
72 | 43 | end
|
73 | 44 |
|
74 | 45 | context '#running?' do
|
|
0 commit comments