Skip to content

Commit

Permalink
[GR-48376] Use larger timeouts in Queue/SizedQueue specs to account f…
Browse files Browse the repository at this point in the history
…or scheduling under high load

PullRequest: truffleruby/4101
  • Loading branch information
eregon committed Jan 3, 2024
2 parents 896c61f + ed74888 commit 20fa986
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
34 changes: 15 additions & 19 deletions spec/ruby/shared/queue/deque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -80,18 +80,17 @@
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
q = @object.call
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
Expand All @@ -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
Expand Down
34 changes: 15 additions & 19 deletions spec/ruby/shared/sizedqueue/enque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 20fa986

Please sign in to comment.