8 require 'sleepy_penguin'
10 class TestEpollOptimizations < Test::Unit::TestCase
12 RBX = defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'rbx')
21 [ @ep, @rd, @wr ].each { |io| io.close unless io.closed? }
25 io, err = Strace.me do
26 @ep.set(@wr, Epoll::OUT)
27 @ep.set(@wr, Epoll::OUT)
30 lines = io.readlines; io.close
31 assert_equal 1, lines.grep(/^epoll_ctl/).size
32 assert_match /EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0]
34 io, err = Strace.me { @ep.set(@wr, Epoll::OUT | Epoll::ONESHOT) }
36 lines = io.readlines; io.close
37 assert_equal 1, lines.grep(/^epoll_ctl/).size
38 assert_match /EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0]
40 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
42 lines = io.readlines; io.close
43 assert_equal 1, lines.grep(/^epoll_ctl/).size
44 assert_match /EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0]
49 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
51 lines = io.readlines; io.close
52 assert_equal 1, lines.grep(/^epoll_ctl/).size
53 assert_match /EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0]
57 @ep.set(@wr, Epoll::OUT)
59 io, err = Strace.me { rv = @ep.delete(@wr) }
62 lines = io.readlines; io.close
63 assert_equal 1, lines.grep(/^epoll_ctl/).size
64 assert_match %r{=\s+0$}, lines.grep(/^epoll_ctl/)[0]
67 io, err = Strace.me { rv = @ep.delete(@wr) }
70 lines = io.readlines; io.close
71 assert_equal 0, lines.grep(/^epoll_ctl/).size
74 def test_delete_closed
76 @ep.set(@wr, Epoll::OUT)
80 assert_equal a, @wr.fileno
82 io, err = Strace.me { rv = @ep.delete(@wr) }
83 lines = io.readlines; io.close
86 assert_equal 0, lines.grep(/^epoll_ctl/).size
89 def test_delete_closed_proxy
90 obj = Struct.new(:to_io).new(@wr)
92 @ep.add(obj, Epoll::OUT)
94 io, err = Strace.me { rv = @ep.delete(obj) }
95 lines = io.readlines; io.close
96 assert_kind_of IOError, err
98 assert_equal 0, lines.grep(/^epoll_ctl/).size
101 def test_delete_closed_fileno
103 @ep.add(fileno, Epoll::OUT)
106 io, err = Strace.me { rv = @ep.delete(fileno) }
107 lines = io.readlines; io.close
109 assert_equal fileno, rv
110 assert_equal 0, lines.grep(/^epoll_ctl/).size
113 def test_delete_aliased_a
114 tmp = IO.for_fd @wr.fileno
116 @ep.set(tmp, Epoll::OUT)
118 io, err = Strace.me { rv = @ep.delete(@wr) }
119 lines = io.readlines; io.close
122 assert_equal 1, lines.grep(/^epoll_ctl/).size
123 assert_match %r{=\s+0$}, lines.grep(/^epoll_ctl/)[0]
124 assert_equal 0, lines.grep(/ENOENT/).size
127 def test_delete_aliased_b
128 tmp = IO.for_fd @wr.fileno
130 @ep.set(@wr, Epoll::OUT)
132 io, err = Strace.me { rv = @ep.delete(tmp) }
133 lines = io.readlines; io.close
136 assert_equal 1, lines.grep(/^epoll_ctl/).size
137 assert_match %r{=\s+0$}, lines.grep(/^epoll_ctl/)[0]
138 assert_equal 0, lines.grep(/ENOENT/).size
141 def test_delete_aliased_closed
142 tmp = IO.for_fd @wr.fileno
144 @ep.set(tmp, Epoll::OUT)
147 io, err = Strace.me { rv = @ep.delete(tmp) }
148 lines = io.readlines; io.close
151 assert_equal 1, lines.grep(/^epoll_ctl/).size
152 assert_equal 1, lines.grep(/EBADF/).size
154 end if defined?(Strace)