Sha256: d553198e33284b1840debe67264ef7a6ef90950d4f03906efda096195e709fae

Contents?: true

Size: 1009 Bytes

Versions: 6

Compression:

Stored size: 1009 Bytes

Contents

require 'test/unit'
require 'io/nonblock'
$-w = true
require 'kgio'

class TestDefaultWait < Test::Unit::TestCase

  def test_socket_pair
    a, b = Kgio::UNIXSocket.pair
    assert_equal a, a.kgio_wait_writable
    a.syswrite('.')
    assert_equal b, b.kgio_wait_readable
  end

  def test_pipe
    a, b = Kgio::Pipe.new
    assert_equal b, b.kgio_wait_writable
    b.syswrite('.')
    assert_equal a, a.kgio_wait_readable
  end

  def test_wait_readable_timed
    a, b = Kgio::Pipe.new
    t0 = Time.now
    assert_nil a.kgio_wait_readable(1.1)
    diff = Time.now - t0
    assert_in_delta diff, 1.1, 0.05

    b.kgio_write '.'
    assert_equal a, a.kgio_wait_readable(1.1)
  end

  def test_wait_writable_timed
    a, b = Kgio::Pipe.new
    buf = "*" * 65536
    true until Symbol === b.kgio_trywrite(buf)
    t0 = Time.now
    assert_nil b.kgio_wait_writable(1.1)
    diff = Time.now - t0
    assert_in_delta diff, 1.1, 0.05

    a.kgio_read(16384)
    assert_equal b, b.kgio_wait_writable(1.1)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kgio-2.7.2 test/test_default_wait.rb
kgio-2.7.1 test/test_default_wait.rb
kgio-2.7.0.3.gfd1e test/test_default_wait.rb
kgio-2.7.0 test/test_default_wait.rb
kgio-2.6.0 test/test_default_wait.rb
kgio-2.5.0 test/test_default_wait.rb