Skip to content

Commit ab5cdf2

Browse files
committed
Do not call subject/let defined methods in after block when the threads are reaped
1 parent e14ccb3 commit ab5cdf2

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

spec/concurrent/atomic/count_down_latch_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444

4545
it 'blocks indefinitely' do
4646
# test the thread is kill-able
47-
in_thread { latch.wait }
47+
in_thread(latch) { |l| l.wait }
48+
sleep 0.1
4849
end
4950

5051
context 'count set to zero' do

spec/concurrent/atomic/event_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ module Concurrent
112112
expect(latch.wait(0.1)).to be true
113113
end
114114

115+
it 'blocks indefinitely' do
116+
in_thread{ subject.wait }
117+
sleep 0.1
118+
end
119+
115120
it 'stops waiting when the timer expires' do
116121
subject.reset
117122
latch = CountDownLatch.new(1)

spec/concurrent/atomic/read_write_lock_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ module Concurrent
8989
latch_2 = Concurrent::CountDownLatch.new(1)
9090
latch_3 = Concurrent::CountDownLatch.new(1)
9191

92-
in_thread do
92+
t1 = in_thread do
9393
latch_1.wait(1)
9494
subject.acquire_write_lock
9595
latch_2.count_down
9696
latch_3.wait(1)
9797
subject.release_write_lock
9898
end
9999

100-
in_thread do
100+
t2 = in_thread do
101101
latch_2.wait(1)
102102
subject.acquire_write_lock
103103
subject.release_write_lock
@@ -109,6 +109,8 @@ module Concurrent
109109
expect(subject).to have_waiters
110110

111111
latch_3.count_down
112+
113+
join_with t1, t2
112114
end
113115
end
114116

spec/concurrent/synchronization_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Concurrent
77
RSpec.shared_examples :attr_volatile do
88

99
specify 'older writes are always visible' do
10+
store = store()
1011
store.not_volatile = 0
1112
store.volatile = 0
1213

spec/support/example_group_extensions.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def in_thread(*args, &block)
3232
t
3333
end
3434

35+
def join_with(*threads, timeout: 0.1)
36+
Array(threads).each { |t| expect(t.join(timeout)).not_to eq nil }
37+
end
3538
end
3639
end
3740

0 commit comments

Comments
 (0)