From ed748887f6a736737a5cde85c022e2a6ce25ca29 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 3 Jan 2024 17:18:57 +0100 Subject: [PATCH] [GR-48376] Use larger timeouts in Queue/SizedQueue specs to account for scheduling under high load * Also cleanup inconsistent formatting for raise_error. --- spec/ruby/shared/queue/deque.rb | 34 ++++++++++++---------------- spec/ruby/shared/sizedqueue/enque.rb | 34 ++++++++++++---------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb index 9e6b45009d29..0abba5301e02 100644 --- a/spec/ruby/shared/queue/deque.rb +++ b/spec/ruby/shared/queue/deque.rb @@ -70,7 +70,7 @@ q = @object.call t = Thread.new { - q.send(@method, timeout: 1).should == 1 + q.send(@method, timeout: TIME_TOLERANCE).should == 1 } Thread.pass until t.status == "sleep" && q.num_waiting == 1 q << 1 @@ -80,10 +80,9 @@ it "returns nil if no item is available in time" do q = @object.call - t = Thread.new { - q.send(@method, timeout: 0.1).should == nil - } - t.join + Thread.new { + q.send(@method, timeout: 0.001).should == nil + }.join end it "does nothing if the timeout is nil" do @@ -91,7 +90,7 @@ t = Thread.new { q.send(@method, timeout: nil).should == 1 } - t.join(0.2).should == nil + Thread.pass until t.status == "sleep" && q.num_waiting == 1 q << 1 t.join end @@ -105,23 +104,20 @@ it "raise TypeError if timeout is not a valid numeric" do q = @object.call - -> { q.send(@method, timeout: "1") }.should raise_error( - TypeError, - "no implicit conversion to float from string", - ) - - -> { q.send(@method, timeout: false) }.should raise_error( - TypeError, - "no implicit conversion to float from false", - ) + -> { + q.send(@method, timeout: "1") + }.should raise_error(TypeError, "no implicit conversion to float from string") + + -> { + q.send(@method, timeout: false) + }.should raise_error(TypeError, "no implicit conversion to float from false") end it "raise ArgumentError if non_block = true is passed too" do q = @object.call - -> { q.send(@method, true, timeout: 1) }.should raise_error( - ArgumentError, - "can't set a timeout if non_block is enabled", - ) + -> { + q.send(@method, true, timeout: 1) + }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled") end it "returns nil for a closed empty queue" do diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb index 7b6b1df7302f..664c4c6f3508 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -55,7 +55,7 @@ q << 1 t = Thread.new { - q.send(@method, 2, timeout: 1).should == q + q.send(@method, 2, timeout: TIME_TOLERANCE).should == q } Thread.pass until t.status == "sleep" && q.num_waiting == 1 q.pop @@ -82,31 +82,27 @@ it "returns nil if no space is available in time" do q = @object.call(1) q << 1 - t = Thread.new { - q.send(@method, 2, timeout: 0.1).should == nil - } - t.join + Thread.new { + q.send(@method, 2, timeout: 0.001).should == nil + }.join end it "raise TypeError if timeout is not a valid numeric" do q = @object.call(1) - -> { q.send(@method, 2, timeout: "1") }.should raise_error( - TypeError, - "no implicit conversion to float from string", - ) - - -> { q.send(@method, 2, timeout: false) }.should raise_error( - TypeError, - "no implicit conversion to float from false", - ) + -> { + q.send(@method, 2, timeout: "1") + }.should raise_error(TypeError, "no implicit conversion to float from string") + + -> { + q.send(@method, 2, timeout: false) + }.should raise_error(TypeError, "no implicit conversion to float from false") end it "raise ArgumentError if non_block = true is passed too" do q = @object.call(1) - -> { q.send(@method, 2, true, timeout: 1) }.should raise_error( - ArgumentError, - "can't set a timeout if non_block is enabled", - ) + -> { + q.send(@method, 2, true, timeout: 1) + }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled") end it "raise ClosedQueueError when closed before enqueued" do @@ -120,7 +116,7 @@ q << 1 t = Thread.new { - -> { q.send(@method, 1, timeout: 10) }.should raise_error(ClosedQueueError, "queue closed") + -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed") } Thread.pass until q.num_waiting == 1