Skip to content

Commit

Permalink
test/fiber/test_queue.rb: Make the stuck test fail.
Browse files Browse the repository at this point in the history
We observed the 2 tests in the `test/fiber/test_queue.rb` getting stuck
in some GCC compilers in ppc64le Ubuntu, even when the timeout
`queue.pop(timeout: 0.0001)` is set in the code.

This commit is to make the test fail rather than getting stuck.
  • Loading branch information
junaruga committed Oct 27, 2023
1 parent 49d4421 commit 2b5f63c
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions test/fiber/test_queue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'timeout'
require 'test/unit'
require_relative 'scheduler'

Expand All @@ -7,16 +8,18 @@ def test_pop_with_timeout
queue = Thread::Queue.new
result = :unspecified

Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler(scheduler)
assert_nothing_stuck do
Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler(scheduler)

Fiber.schedule do
result = queue.pop(timeout: 0.0001)
end
Fiber.schedule do
result = queue.pop(timeout: 0.0001)
end

scheduler.run
end.join
scheduler.run
end.join
end

assert_nil result
end
Expand All @@ -26,17 +29,28 @@ def test_pop_with_timeout_and_value
queue.push(:something)
result = :unspecified

Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler(scheduler)
assert_nothing_stuck do
Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler(scheduler)

Fiber.schedule do
result = queue.pop(timeout: 0.0001)
end
Fiber.schedule do
result = queue.pop(timeout: 0.0001)
end

scheduler.run
end.join
scheduler.run
end.join
end

assert_equal :something, result
end

def assert_nothing_stuck(&block)
msg = 'The test gets stuck due to a possible compiler bug.'
assert_nothing_raised(Timeout::Error, msg) do
Timeout::timeout(1) do
block.call
end
end
end
end

0 comments on commit 2b5f63c

Please sign in to comment.