sleepy_penguin.git  about / heads / tags
Linux I/O events for Ruby
blob cebf24ecb648d2a14bf80c90726956d7c0c74e9d 968 bytes (raw)
$ git show HEAD:test/test_epoll_gc.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
36
37
38
39
40
41
42
43
44
45
46
 
require_relative 'helper'

class TestEpollGC < Test::Unit::TestCase
  include SleepyPenguin

  def setup
    GC.stress = true if GC.respond_to?(:stress=)
    @ep = Epoll.new
  end

  def teardown
    GC.stress = false if GC.respond_to?(:stress=)
  end

  def add_pipe_no_tailcall(m, depth)
    add_pipe(m, depth += 1)
  end

  def add_pipe(m, depth = 0)
    if depth > 6000
      _, wr = IO.pipe
      warn "wr: #{wr.fileno}"
      @ep.__send__(m, wr, Epoll::OUT)
    else
      add_pipe_no_tailcall(m, depth + 1)
    end
  end

  def test_gc_safety
    done = false
    begin
      if done
        x = nil
        @ep.wait(nil, 10) { |flags, obj| p [  flags, x = obj ] }
        assert x, "#{x.inspect}"
        break
      else
        add_pipe(:add)
        2048.times { IO.pipe; File.open(__FILE__)}
        done = true
      end
    rescue Errno::EMFILE, Errno::ENFILE
      Thread.new { GC.start }.join
    end while true
  end
end if ENV["GC_STRESS"].to_i != 0

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