aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar apolcyn <apolcyn@google.com>2017-04-11 16:53:55 -0700
committerGravatar GitHub <noreply@github.com>2017-04-11 16:53:55 -0700
commitf200f25d4dad5b74e7216a2b17fa2c2783ceb40e (patch)
treed1fccafcd703bfa30f337798714b657f60fa7b36 /src
parentc3f494558b6cefd99cec7d8b62e94c6ffbc664d6 (diff)
parent9b020019497f5fb9fb035027d55d350450fb4ed0 (diff)
Merge pull request #10564 from apolcyn/deflake_ruby_test
fix flakey race in ruby tests
Diffstat (limited to 'src')
-rw-r--r--src/ruby/spec/generic/rpc_server_pool_spec.rb44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/ruby/spec/generic/rpc_server_pool_spec.rb b/src/ruby/spec/generic/rpc_server_pool_spec.rb
index 69e8222cb9..0803ca74ed 100644
--- a/src/ruby/spec/generic/rpc_server_pool_spec.rb
+++ b/src/ruby/spec/generic/rpc_server_pool_spec.rb
@@ -52,28 +52,31 @@ describe GRPC::Pool do
expect(p.ready_for_work?).to be(false)
end
- it 'it stops being ready after all workers jobs waiting or running' do
+ it 'it stops being ready after all workers are busy' do
p = Pool.new(5)
p.start
- job = proc { sleep(3) } # sleep so workers busy when done scheduling
- 5.times do
- expect(p.ready_for_work?).to be(true)
- p.schedule(&job)
+
+ wait_mu = Mutex.new
+ wait_cv = ConditionVariable.new
+ wait = true
+
+ job = proc do
+ wait_mu.synchronize do
+ wait_cv.wait(wait_mu) while wait
+ end
end
- expect(p.ready_for_work?).to be(false)
- end
- it 'it becomes ready again after jobs complete' do
- p = Pool.new(5)
- p.start
- job = proc {}
5.times do
expect(p.ready_for_work?).to be(true)
p.schedule(&job)
end
+
expect(p.ready_for_work?).to be(false)
- sleep 5 # give the pool time do get at least one task done
- expect(p.ready_for_work?).to be(true)
+
+ wait_mu.synchronize do
+ wait = false
+ wait_cv.broadcast
+ end
end
end
@@ -105,13 +108,20 @@ describe GRPC::Pool do
it 'stops jobs when there are long running jobs' do
p = Pool.new(1)
p.start
- o, q = Object.new, Queue.new
+
+ wait_forever_mu = Mutex.new
+ wait_forever_cv = ConditionVariable.new
+ wait_forever = true
+
+ job_running = Queue.new
job = proc do
- sleep(5) # long running
- q.push(o)
+ job_running.push(Object.new)
+ wait_forever_mu.synchronize do
+ wait_forever_cv.wait while wait_forever
+ end
end
p.schedule(&job)
- sleep(1) # should ensure the long job gets scheduled
+ job_running.pop
expect { p.stop }.not_to raise_error
end
end