Skip to content

Commit ed74888

Browse files
committed
[GR-48376] Use larger timeouts in Queue/SizedQueue specs to account for scheduling under high load
* Also cleanup inconsistent formatting for raise_error.
1 parent 896c61f commit ed74888

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

spec/ruby/shared/queue/deque.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
q = @object.call
7171

7272
t = Thread.new {
73-
q.send(@method, timeout: 1).should == 1
73+
q.send(@method, timeout: TIME_TOLERANCE).should == 1
7474
}
7575
Thread.pass until t.status == "sleep" && q.num_waiting == 1
7676
q << 1
@@ -80,18 +80,17 @@
8080
it "returns nil if no item is available in time" do
8181
q = @object.call
8282

83-
t = Thread.new {
84-
q.send(@method, timeout: 0.1).should == nil
85-
}
86-
t.join
83+
Thread.new {
84+
q.send(@method, timeout: 0.001).should == nil
85+
}.join
8786
end
8887

8988
it "does nothing if the timeout is nil" do
9089
q = @object.call
9190
t = Thread.new {
9291
q.send(@method, timeout: nil).should == 1
9392
}
94-
t.join(0.2).should == nil
93+
Thread.pass until t.status == "sleep" && q.num_waiting == 1
9594
q << 1
9695
t.join
9796
end
@@ -105,23 +104,20 @@
105104

106105
it "raise TypeError if timeout is not a valid numeric" do
107106
q = @object.call
108-
-> { q.send(@method, timeout: "1") }.should raise_error(
109-
TypeError,
110-
"no implicit conversion to float from string",
111-
)
112-
113-
-> { q.send(@method, timeout: false) }.should raise_error(
114-
TypeError,
115-
"no implicit conversion to float from false",
116-
)
107+
-> {
108+
q.send(@method, timeout: "1")
109+
}.should raise_error(TypeError, "no implicit conversion to float from string")
110+
111+
-> {
112+
q.send(@method, timeout: false)
113+
}.should raise_error(TypeError, "no implicit conversion to float from false")
117114
end
118115

119116
it "raise ArgumentError if non_block = true is passed too" do
120117
q = @object.call
121-
-> { q.send(@method, true, timeout: 1) }.should raise_error(
122-
ArgumentError,
123-
"can't set a timeout if non_block is enabled",
124-
)
118+
-> {
119+
q.send(@method, true, timeout: 1)
120+
}.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
125121
end
126122

127123
it "returns nil for a closed empty queue" do

spec/ruby/shared/sizedqueue/enque.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
q << 1
5656

5757
t = Thread.new {
58-
q.send(@method, 2, timeout: 1).should == q
58+
q.send(@method, 2, timeout: TIME_TOLERANCE).should == q
5959
}
6060
Thread.pass until t.status == "sleep" && q.num_waiting == 1
6161
q.pop
@@ -82,31 +82,27 @@
8282
it "returns nil if no space is available in time" do
8383
q = @object.call(1)
8484
q << 1
85-
t = Thread.new {
86-
q.send(@method, 2, timeout: 0.1).should == nil
87-
}
88-
t.join
85+
Thread.new {
86+
q.send(@method, 2, timeout: 0.001).should == nil
87+
}.join
8988
end
9089

9190
it "raise TypeError if timeout is not a valid numeric" do
9291
q = @object.call(1)
93-
-> { q.send(@method, 2, timeout: "1") }.should raise_error(
94-
TypeError,
95-
"no implicit conversion to float from string",
96-
)
97-
98-
-> { q.send(@method, 2, timeout: false) }.should raise_error(
99-
TypeError,
100-
"no implicit conversion to float from false",
101-
)
92+
-> {
93+
q.send(@method, 2, timeout: "1")
94+
}.should raise_error(TypeError, "no implicit conversion to float from string")
95+
96+
-> {
97+
q.send(@method, 2, timeout: false)
98+
}.should raise_error(TypeError, "no implicit conversion to float from false")
10299
end
103100

104101
it "raise ArgumentError if non_block = true is passed too" do
105102
q = @object.call(1)
106-
-> { q.send(@method, 2, true, timeout: 1) }.should raise_error(
107-
ArgumentError,
108-
"can't set a timeout if non_block is enabled",
109-
)
103+
-> {
104+
q.send(@method, 2, true, timeout: 1)
105+
}.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
110106
end
111107

112108
it "raise ClosedQueueError when closed before enqueued" do
@@ -120,7 +116,7 @@
120116
q << 1
121117

122118
t = Thread.new {
123-
-> { q.send(@method, 1, timeout: 10) }.should raise_error(ClosedQueueError, "queue closed")
119+
-> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed")
124120
}
125121

126122
Thread.pass until q.num_waiting == 1

0 commit comments

Comments
 (0)