sleepy_penguin.git  about / heads / tags
Linux I/O events for Ruby
blob 56a38083781f77dfcf77c5b5ddfd896ce936e0da 738 bytes (raw)
$ git show v3.4.1:test/test_epoll_io.rb	# shows this blob on the CLI

 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
 
require './test/helper'
require 'fcntl'
require 'socket'
require 'thread'
$-w = true
Thread.abort_on_exception = true
require 'sleepy_penguin'

class TestEpollIO < Testcase
  include SleepyPenguin

  def setup
    @rd, @wr = IO.pipe
    @epio = Epoll::IO.new(nil)
  end

  def test_add_wait
    @epio.epoll_ctl(Epoll::CTL_ADD, @wr, Epoll::OUT)
    ev = []
    @epio.epoll_wait { |events, obj| ev << [ events, obj ] }
    assert_equal([[Epoll::OUT, @wr]], ev)
  end

  class EpSub < Epoll::IO
    def self.new
      super(SleepyPenguin::Epoll::CLOEXEC)
    end
  end

  def test_subclass
    tmp = EpSub.new
    assert_equal Fcntl::FD_CLOEXEC, tmp.fcntl(Fcntl::F_GETFD)
    assert_nil tmp.close
  end
end if defined?(SleepyPenguin::Epoll)

git clone https://yhbt.net/sleepy_penguin.git