Skip to content

Commit 7051d2f

Browse files
committed
Make tests tolerate varied shutdown behaviors
1 parent 8bea918 commit 7051d2f

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

spec/concurrent/executor/executor_service_shared.rb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,22 @@
1616
latch = Concurrent::CountDownLatch.new(1)
1717
subject.post{ sleep(1) }
1818
subject.shutdown
19-
subject.post{ latch.count_down }
19+
begin
20+
subject.post{ latch.count_down }
21+
rescue Concurrent::RejectedExecutionError
22+
end
2023
expect(latch.wait(0.1)).to be_falsey
2124
end
2225

23-
it 'returns false while shutting down' do
24-
subject.post{ sleep(1) }
25-
subject.shutdown
26-
expect(subject.post{ nil }).to be_falsey
27-
end
28-
2926
it 'rejects the block once shutdown' do
3027
subject.shutdown
3128
latch = Concurrent::CountDownLatch.new(1)
32-
subject.post{ sleep(1) }
33-
subject.post{ latch.count_down }
29+
begin
30+
subject.post{ latch.count_down }
31+
rescue Concurrent::RejectedExecutionError
32+
end
3433
expect(latch.wait(0.1)).to be_falsey
3534
end
36-
37-
it 'returns false once shutdown' do
38-
subject.post{ nil }
39-
subject.shutdown
40-
sleep(0.1)
41-
expect(subject.post{ nil }).to be_falsey
42-
end
4335
end
4436

4537
context '#running?' do
@@ -75,7 +67,10 @@
7567
latch2 = Concurrent::CountDownLatch.new(1)
7668
subject.post{ sleep(0.2); latch1.count_down }
7769
subject.shutdown
78-
expect(subject.post{ latch2.count_down }).to be_falsey
70+
begin
71+
expect(subject.post{ latch2.count_down }).to be_falsey
72+
rescue Concurrent::RejectedExecutionError
73+
end
7974
expect(latch1.wait(1)).to be_truthy
8075
expect(latch2.wait(0.2)).to be_falsey
8176
end
@@ -121,7 +116,10 @@
121116
subject.post{ sleep(0.1); expected.increment }
122117
subject.post{ sleep(0.1); expected.increment }
123118
subject.shutdown
124-
subject.post{ expected.increment }
119+
begin
120+
subject.post{ expected.increment }
121+
rescue Concurrent::RejectedExecutionError
122+
end
125123
subject.wait_for_termination(1)
126124
expect(expected.value).to eq(2)
127125
end
@@ -135,7 +133,10 @@
135133
subject.post{ sleep(0.1); latch.count_down }
136134
latch.wait(1)
137135
subject.kill
138-
expect(subject.post{ expected.make_true }).to be_falsey
136+
begin
137+
expect(subject.post{ expected.make_true }).to be_falsey
138+
rescue Concurrent::RejectedExecutionError
139+
end
139140
sleep(0.1)
140141
expect(expected.value).to be_falsey
141142
end
@@ -145,7 +146,10 @@
145146
sleep(0.1)
146147
subject.kill
147148
sleep(0.1)
148-
expect(subject.post{ nil }).to be_falsey
149+
begin
150+
expect(subject.post{ nil }).to be_falsey
151+
rescue Concurrent::RejectedExecutionError
152+
end
149153
end
150154
end
151155

spec/concurrent/executor/ruby_thread_pool_executor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ module Concurrent
208208
latch.wait(0.1)
209209
end
210210

211-
specify '#<< executes the task on the current thread when the queue is at capacity' do
211+
specify '#<< executes the task on the current thread when the executor is shutting down' do
212212
latch = Concurrent::CountDownLatch.new(1)
213213
subject.shutdown
214214
subject << proc { latch.count_down }

0 commit comments

Comments
 (0)