File: test_default_wait.rb

package info (click to toggle)
ruby-kgio 2.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 504 kB
  • sloc: ruby: 2,779; ansic: 2,017; sh: 32; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (4)
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
47
48
49
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.2

    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.2

    # Read enough to ensure one kernel buffer is cleared
    # to ensure that poll et al will start saying we have
    # enough space to allow a write.  This should be at
    # least the largest system page size we support.
    a.kgio_read(65536)
    assert_equal b, b.kgio_wait_writable(1.1)
  end
end