tests: remove tests for IO#nonblock? after accept
[kgio.git] / test / lib_server_accept.rb
blobccf89d826ad8b9909d9f5fc3dc83bcc5a135642d
1 require 'test/unit'
2 require 'fcntl'
3 require 'io/nonblock'
4 $-w = true
5 require 'kgio'
7 module LibServerAccept
9   def teardown
10     @srv.close unless @srv.closed?
11     Kgio.accept_cloexec = true
12     Kgio.accept_nonblock = false
13   end
15   def test_tryaccept_success
16     a = client_connect
17     IO.select([@srv])
18     b = @srv.kgio_tryaccept
19     assert_kind_of Kgio::Socket, b
20     assert_equal @host, b.kgio_addr
21   end
23   def test_tryaccept_flags
24     a = client_connect
25     IO.select([@srv])
26     b = @srv.kgio_tryaccept nil, 0
27     assert_kind_of Kgio::Socket, b
28     assert_equal 0, b.fcntl(Fcntl::F_GETFD)
29   end
31   def test_blocking_accept_flags
32     a = client_connect
33     IO.select([@srv])
34     b = @srv.kgio_accept nil, 0
35     assert_kind_of Kgio::Socket, b
36     assert_equal 0, b.fcntl(Fcntl::F_GETFD)
37   end
39   def test_tryaccept_fail
40     assert_equal nil, @srv.kgio_tryaccept
41   end
43   def test_blocking_accept
44     t0 = Time.now
45     pid = fork { sleep 1; a = client_connect; sleep }
46     b = @srv.kgio_accept
47     elapsed = Time.now - t0
48     assert_kind_of Kgio::Socket, b
49     assert_equal @host, b.kgio_addr
50     Process.kill(:TERM, pid)
51     Process.waitpid(pid)
52     assert elapsed >= 1, "elapsed: #{elapsed}"
53   end
55   def test_blocking_accept_with_nonblock_socket
56     @srv.nonblock = true
57     t0 = Time.now
58     pid = fork { sleep 1; a = client_connect; sleep }
59     b = @srv.kgio_accept
60     elapsed = Time.now - t0
61     assert_kind_of Kgio::Socket, b
62     assert_equal @host, b.kgio_addr
63     Process.kill(:TERM, pid)
64     Process.waitpid(pid)
65     assert elapsed >= 1, "elapsed: #{elapsed}"
67     t0 = Time.now
68     pid = fork { sleep 6; a = client_connect; sleep }
69     b = @srv.kgio_accept
70     elapsed = Time.now - t0
71     assert_kind_of Kgio::Socket, b
72     assert_equal @host, b.kgio_addr
73     Process.kill(:TERM, pid)
74     Process.waitpid(pid)
75     assert elapsed >= 6, "elapsed: #{elapsed}"
77     t0 = Time.now
78     pid = fork { sleep 1; a = client_connect; sleep }
79     b = @srv.kgio_accept
80     elapsed = Time.now - t0
81     assert_kind_of Kgio::Socket, b
82     assert_equal @host, b.kgio_addr
83     Process.kill(:TERM, pid)
84     Process.waitpid(pid)
85     assert elapsed >= 1, "elapsed: #{elapsed}"
86   end
87 end