summaryrefslogtreecommitdiff
path: root/test/scheduler/test_io.rb
blob: ef46d1ac2cf223aee188eb2a1ee0adcca212c8ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true
require 'test/unit'
require_relative 'scheduler'

class TestSchedulerIO < Test::Unit::TestCase
  MESSAGE = "Hello World"

  def test_read
    skip unless defined?(UNIXSocket)

    i, o = UNIXSocket.pair
    skip unless i.nonblock? && o.nonblock?

    message = nil

    thread = Thread.new do
      scheduler = Scheduler.new
      Thread.current.scheduler = scheduler

      Fiber do
        message = i.read(20)
        i.close
      end

      Fiber do
        o.write("Hello World")
        o.close
      end
    end

    thread.join

    assert_equal MESSAGE, message
  end
end