mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move test/scheduler
-> test/fiber
[Bug #16892][ruby-core:98366].
This commit is contained in:
parent
39365b46e2
commit
6fa8455ebb
Notes:
git
2020-05-15 10:26:48 +09:00
8 changed files with 0 additions and 0 deletions
45
test/fiber/test_enumerator.rb
Normal file
45
test/fiber/test_enumerator.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
require 'test/unit'
|
||||
require 'socket'
|
||||
require_relative 'scheduler'
|
||||
|
||||
class TestSchedulerEnumerator < Test::Unit::TestCase
|
||||
MESSAGE = "Hello World"
|
||||
|
||||
def test_read_characters
|
||||
skip unless defined?(UNIXSocket)
|
||||
|
||||
i, o = UNIXSocket.pair
|
||||
skip unless i.nonblock? && o.nonblock?
|
||||
|
||||
message = String.new
|
||||
|
||||
thread = Thread.new do
|
||||
scheduler = Scheduler.new
|
||||
Thread.current.scheduler = scheduler
|
||||
|
||||
e = i.to_enum(:each_char)
|
||||
|
||||
Fiber do
|
||||
o.write("Hello World")
|
||||
o.close
|
||||
end
|
||||
|
||||
Fiber do
|
||||
begin
|
||||
while c = e.next
|
||||
message << c
|
||||
end
|
||||
rescue StopIteration
|
||||
# Ignore.
|
||||
end
|
||||
|
||||
i.close
|
||||
end
|
||||
end
|
||||
|
||||
thread.join
|
||||
|
||||
assert_equal(MESSAGE, message)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue