aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2017-04-11 10:14:13 -0700
committerGravatar Alexander Polcyn <apolcyn@google.com>2017-04-11 10:14:13 -0700
commit9b020019497f5fb9fb035027d55d350450fb4ed0 (patch)
tree9944718216030ce00a30101f2f1c3e3433fd4172 /src/ruby
parentd6dd46a1d9558c32ed17f1e9ce1726b272b06404 (diff)
get rid of racey sleep 5 and use a cv to wait forever
Diffstat (limited to 'src/ruby')
-rw-r--r--src/ruby/spec/generic/rpc_server_pool_spec.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ruby/spec/generic/rpc_server_pool_spec.rb b/src/ruby/spec/generic/rpc_server_pool_spec.rb
index 75b4022568..0803ca74ed 100644
--- a/src/ruby/spec/generic/rpc_server_pool_spec.rb
+++ b/src/ruby/spec/generic/rpc_server_pool_spec.rb
@@ -52,8 +52,7 @@ describe GRPC::Pool do
expect(p.ready_for_work?).to be(false)
end
- it 'it stops being ready after all workers are busy, ' \
- 'and it becomes ready again after jobs complete' do
+ it 'it stops being ready after all workers are busy' do
p = Pool.new(5)
p.start
@@ -78,11 +77,6 @@ describe GRPC::Pool do
wait = false
wait_cv.broadcast
end
-
- # There's a potential race here but it shouldn't ever be
- # reached with a 5 second sleep.
- sleep 5
- expect(p.ready_for_work?).to be(true)
end
end
@@ -114,10 +108,17 @@ describe GRPC::Pool do
it 'stops jobs when there are long running jobs' do
p = Pool.new(1)
p.start
+
+ wait_forever_mu = Mutex.new
+ wait_forever_cv = ConditionVariable.new
+ wait_forever = true
+
job_running = Queue.new
job = proc do
job_running.push(Object.new)
- sleep(5000)
+ wait_forever_mu.synchronize do
+ wait_forever_cv.wait while wait_forever
+ end
end
p.schedule(&job)
job_running.pop