Skip to content

Commit 0f49c5e

Browse files
committed
stabilize tests
1 parent 06634ef commit 0f49c5e

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

spec/concurrent/synchronization_spec.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Concurrent
77
RSpec.shared_examples :attr_volatile do
88

99
specify 'older writes are always visible' do
10-
store = store()
10+
store = store()
1111
store.not_volatile = 0
1212
store.volatile = 0
1313

@@ -120,12 +120,12 @@ def ns_initialize
120120
describe '#wait' do
121121

122122
it 'puts the current thread to sleep' do
123-
t = in_thread do
123+
t1 = in_thread do
124124
Thread.abort_on_exception = true
125125
subject.wait
126126
end
127-
sleep 0.1
128-
expect(t.status).to eq 'sleep'
127+
t2 = in_thread { Thread.pass until t1.status == 'sleep' }
128+
join_with t2, timeout: 5
129129
end
130130

131131
it 'allows the sleeping thread to be killed' do
@@ -142,29 +142,25 @@ def ns_initialize
142142

143143
it 'releases the lock on the current object' do
144144
t1 = in_thread do
145+
# #wait should release lock, even if it was already held on entry
145146
t2 = in_thread { subject.wait }
146-
sleep 0.1
147-
# TODO (pitr-ch 15-Oct-2016): https://travis-ci.org/pitr-ch/concurrent-ruby/jobs/167933569
148-
status = t2.status
149-
subject.synchronize {} # we will deadlock here if #wait doesn't release lock
147+
Thread.pass until t2.status == 'sleep'
148+
subject.synchronize {} # it will deadlock here if #wait doesn't release lock
149+
t2
150150
end
151-
152-
join_with t1
153-
expect(t1.value).to eq 'sleep'
151+
join_with t1, timeout: 5
152+
expect(t1.value.status).to eq 'sleep'
154153
end
155154

156155
it 'can be called from within a #synchronize block' do
157156
t1 = in_thread do
158-
# #wait should release lock, even if it was already held on entry
159157
t2 = in_thread { subject.synchronize { subject.wait } }
160-
sleep 0.1
161-
status = t2.status
162-
subject.synchronize {} # we will deadlock here if lock wasn't released
163-
status
158+
Thread.pass until t2.status == 'sleep'
159+
subject.synchronize {} # it will deadlock here if #wait doesn't release lock
160+
t2
164161
end
165-
166-
join_with t1
167-
expect(t1.value).to eq 'sleep'
162+
join_with t1, timeout: 5
163+
expect(t1.value.status).to eq 'sleep'
168164
end
169165
end
170166

0 commit comments

Comments
 (0)