Sha256: f059fc7dfec04b0bf5dbb1691f8290e25bc44f87bad041bd7e6d87ce136242cd

Contents?: true

Size: 999 Bytes

Versions: 2

Compression:

Stored size: 999 Bytes

Contents

require 'test/unit'
$-w = true

require 'sleepy_penguin'

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sleepy_penguin-3.2.0 test/test_epoll_gc.rb
sleepy_penguin-3.1.0.26.g7181 test/test_epoll_gc.rb