Add tests for Queue#pop
with fiber scheduler. (#6953)
This commit is contained in:
parent
297df92407
commit
9da5a7e79d
Notes:
git
2022-12-17 07:43:41 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
42
test/fiber/test_queue.rb
Normal file
42
test/fiber/test_queue.rb
Normal file
@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test/unit'
|
||||
require_relative 'scheduler'
|
||||
|
||||
class TestFiberQueue < Test::Unit::TestCase
|
||||
def test_pop_with_timeout
|
||||
queue = Thread::Queue.new
|
||||
result = :unspecified
|
||||
|
||||
Thread.new do
|
||||
scheduler = Scheduler.new
|
||||
Fiber.set_scheduler(scheduler)
|
||||
|
||||
Fiber.schedule do
|
||||
result = queue.pop(timeout: 0.0001)
|
||||
end
|
||||
|
||||
scheduler.run
|
||||
end.join
|
||||
|
||||
assert_nil result
|
||||
end
|
||||
|
||||
def test_pop_with_timeout_and_value
|
||||
queue = Thread::Queue.new
|
||||
queue.push(:something)
|
||||
result = :unspecified
|
||||
|
||||
Thread.new do
|
||||
scheduler = Scheduler.new
|
||||
Fiber.set_scheduler(scheduler)
|
||||
|
||||
Fiber.schedule do
|
||||
result = queue.pop(timeout: 0.0001)
|
||||
end
|
||||
|
||||
scheduler.run
|
||||
end.join
|
||||
|
||||
assert_equal :something, result
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user