6 @host = ENV["TEST_HOST"] || '127.0.0.1'
7 @srv = TCPServer.new(@host, 0)
12 sock = MogileFS::Socket.start(@host, @port)
13 assert_instance_of MogileFS::Socket, sock, sock.inspect
14 assert_nothing_raised do
16 sock.write_nonblock("a")
20 thr = Thread.new { @srv.accept }
22 assert_instance_of TCPSocket, accepted, accepted.inspect
27 sock = MogileFS::Socket.tcp(@host, @port)
28 assert_instance_of MogileFS::Socket, sock, sock.inspect
29 assert_nothing_raised do
30 sock.write_nonblock("a")
32 thr = Thread.new { @srv.accept }
34 assert_instance_of TCPSocket, accepted, accepted.inspect
35 assert_equal "a", accepted.read(1)
40 sock = MogileFS::Socket.tcp(@host, @port)
41 accepted = @srv.accept
43 assert_raises(MogileFS::UnreadableSocketError) do
44 sock.timed_peek(2, buf, 0.01)
47 assert_equal "HI", sock.timed_peek(2, buf, 0.1)
48 assert_equal "HI", buf
49 assert_equal "HI", sock.timed_peek(2, buf)
50 assert_equal "HI", sock.timed_read(2, buf)
52 assert_nil sock.timed_peek(2, buf)
56 sock = MogileFS::Socket.tcp(@host, @port)
57 accepted = @srv.accept
59 assert_raises(MogileFS::UnreadableSocketError) do
60 sock.timed_read(2, buf, 0.01)
63 assert_equal "HI", sock.timed_read(2, buf, 0.1)
64 assert_equal "HI", buf
65 assert_raises(MogileFS::UnreadableSocketError) do
66 sock.timed_read(2, buf, 0.01)
69 assert_nil sock.timed_read(2, buf)
73 sock = MogileFS::Socket.tcp(@host, @port)
74 accepted = @srv.accept
77 assert_raises(MogileFS::RequestTruncatedError) do
79 sock.timed_write(buf, 0.01)
83 tmp = accepted.read(written)
84 assert_equal written, tmp.size
88 sock = MogileFS::Socket.tcp(@host, @port)
89 accepted = @srv.accept
90 assert_raises(MogileFS::UnreadableSocketError) { sock.timed_gets(0.01) }
92 assert_raises(MogileFS::UnreadableSocketError) { sock.timed_gets(0.01) }
94 assert_equal "HI\n", sock.timed_gets
96 assert_nil sock.timed_gets