Sha256: 2c63140739907e297c7fc2b3b8371493679216f90a694252f3dec9cb64b50085
Contents?: true
Size: 1.73 KB
Versions: 16
Compression:
Stored size: 1.73 KB
Contents
require 'test/unit' require 'io/nonblock' $-w = true require 'kgio' module LibServerAccept def teardown @srv.close unless @srv.closed? Kgio.accept_cloexec = true Kgio.accept_nonblock = false end def test_tryaccept_success a = client_connect IO.select([@srv]) b = @srv.kgio_tryaccept assert_kind_of Kgio::Socket, b assert_equal @host, b.kgio_addr end def test_tryaccept_fail assert_equal nil, @srv.kgio_tryaccept end def test_blocking_accept t0 = Time.now pid = fork { sleep 1; a = client_connect; sleep } b = @srv.kgio_accept elapsed = Time.now - t0 assert_kind_of Kgio::Socket, b assert_equal @host, b.kgio_addr Process.kill(:TERM, pid) Process.waitpid(pid) assert elapsed >= 1, "elapsed: #{elapsed}" end def test_blocking_accept_with_nonblock_socket @srv.nonblock = true t0 = Time.now pid = fork { sleep 1; a = client_connect; sleep } b = @srv.kgio_accept elapsed = Time.now - t0 assert_kind_of Kgio::Socket, b assert_equal @host, b.kgio_addr Process.kill(:TERM, pid) Process.waitpid(pid) assert elapsed >= 1, "elapsed: #{elapsed}" t0 = Time.now pid = fork { sleep 6; a = client_connect; sleep } b = @srv.kgio_accept elapsed = Time.now - t0 assert_kind_of Kgio::Socket, b assert_equal @host, b.kgio_addr Process.kill(:TERM, pid) Process.waitpid(pid) assert elapsed >= 6, "elapsed: #{elapsed}" t0 = Time.now pid = fork { sleep 1; a = client_connect; sleep } b = @srv.kgio_accept elapsed = Time.now - t0 assert_kind_of Kgio::Socket, b assert_equal @host, b.kgio_addr Process.kill(:TERM, pid) Process.waitpid(pid) assert elapsed >= 1, "elapsed: #{elapsed}" end end
Version data entries
16 entries across 16 versions & 1 rubygems