File tree Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -106,28 +106,44 @@ def subject.simulate_spurious_wake_up
106
106
end
107
107
108
108
it 'should resist to spurious wake ups without timeout' do
109
- @expected = false
110
- Thread . new { subject . wait ; @ expected = true }
109
+ latch = Concurrent :: CountDownLatch . new ( 1 )
110
+ expected = false
111
111
112
- sleep ( 0.1 )
112
+ t = Thread . new do
113
+ latch . wait ( 1 )
114
+ subject . wait
115
+ expected = true
116
+ end
117
+
118
+ latch . count_down
119
+ t . join ( 0.1 )
113
120
subject . simulate_spurious_wake_up
114
121
115
- sleep ( 0.1 )
116
- expect ( @ expected) . to be_falsey
122
+ t . join ( 0.1 )
123
+ expect ( expected ) . to be_falsey
117
124
end
118
125
119
126
it 'should resist to spurious wake ups with timeout' do
120
- @expected = false
121
- Thread . new { subject . wait ( 0.5 ) ; @expected = true }
127
+ start_latch = Concurrent ::CountDownLatch . new ( 1 )
128
+ finish_latch = Concurrent ::CountDownLatch . new ( 1 )
129
+ expected = false
130
+
131
+ t = Thread . new do
132
+ start_latch . wait ( 1 )
133
+ subject . wait ( 0.5 )
134
+ expected = true
135
+ finish_latch . count_down
136
+ end
122
137
123
- sleep ( 0.1 )
138
+ start_latch . count_down
139
+ t . join ( 0.1 )
124
140
subject . simulate_spurious_wake_up
125
141
126
- sleep ( 0.1 )
127
- expect ( @ expected) . to be_falsey
142
+ t . join ( 0.1 )
143
+ expect ( expected ) . to be_falsey
128
144
129
- sleep ( 0.4 )
130
- expect ( @ expected) . to be_truthy
145
+ finish_latch . wait ( 1 )
146
+ expect ( expected ) . to be_truthy
131
147
end
132
148
end
133
149
end
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ module Concurrent
106
106
start = Time . now . to_f
107
107
subject . post ( 0.2 ) { latch . count_down }
108
108
expect ( latch . wait ( 1 ) ) . to be true
109
- expect ( Time . now . to_f - start ) . to be_within ( 0.1 ) . of ( 0.2 )
109
+ expect ( Time . now . to_f - start ) . to be >= 0.2
110
110
end
111
111
112
112
it 'executes all tasks scheduled for the same time' do
You can’t perform that action at this time.
0 commit comments