@@ -43,25 +43,32 @@ close(s)
4343push! (l, (" IOBuffer" , io))
4444
4545
46- # TCPSocket
46+ function run_test_server (srv, text)
47+ push! (tasks, @async begin
48+ try
49+ sock = accept (srv)
50+ try
51+ write (sock,text)
52+ catch e
53+ if typeof (e) != Base. UVError
54+ rethrow (e)
55+ end
56+ finally
57+ close (sock)
58+ end
59+ finally
60+ close (srv)
61+ end
62+ end )
63+ yield ()
64+ end
4765
48- # PR#14627
49- Base. connect! (sock:: TCPSocket , addr:: Base.InetAddr ) = Base. connect! (sock, addr. host, addr. port)
5066
51- addr = Base . InetAddr ( ip " 127.0.0.1 " , 4444 )
67+ # TCPSocket
5268io = (text) -> begin
53- c = Condition ()
54- tsk = @async begin
55- srv = listen (addr)
56- notify (c)
57- sock = accept (srv)
58- write (sock,text)
59- close (sock)
60- close (srv)
61- end
62- push! (tasks, tsk)
63- wait (c)
64- connect (addr)
69+ port, srv = listenany (rand (2000 : 4000 ))
70+ run_test_server (srv, text)
71+ connect (port)
6572end
6673s = io (text)
6774@test isa (s, IO)
@@ -70,22 +77,13 @@ close(s)
7077push! (l, (" TCPSocket" , io))
7178
7279
73- @windows ? nothing : begin
74-
7580# PipeEndpoint
76- socketname = joinpath (dir, " socket" )
7781io = (text)-> begin
78- c = Condition ()
79- tsk = @async begin
80- con = listen (socketname)
81- notify (c)
82- sock = accept (con)
83- try write (sock,text) end
84- close (sock)
85- close (con)
86- end
87- push! (tasks, tsk)
88- wait (c)
82+ a = " \\\\ .\\ pipe\\ uv-test-$(randstring (6 )) "
83+ b = joinpath (dir, " socket-$(randstring (6 )) " )
84+ socketname = @windows ? a : b
85+ srv = listen (socketname)
86+ run_test_server (srv, text)
8987 connect (socketname)
9088end
9189s = io (text)
@@ -95,6 +93,8 @@ close(s)
9593push! (l, (" PipeEndpoint" , io))
9694
9795
96+ @windows ? nothing : begin
97+
9898# Pipe
9999io = (text) -> open (` echo -n $text ` )[1 ]
100100s = io (text)
@@ -121,13 +121,7 @@ for (name, f) in l
121121
122122 io = ()-> (s= f (text); push! (open_streams, s); s)
123123
124- verbose && println (" $name readall..." )
125- @test readall (io ()) == text
126- @test readall (io ()) == readall (filename)
127-
128124 verbose && println (" $name read..." )
129- @test readbytes (io ()) == Vector {UInt8} (text)
130- @test readbytes (io ()) == open (readbytes,filename)
131125 @test read (io (), UInt8) == read (IOBuffer (text), UInt8)
132126 @test read (io (), UInt8) == open (io-> read (io, UInt8), filename)
133127 @test read (io (), Int) == read (IOBuffer (text), Int)
@@ -145,11 +139,6 @@ for (name, f) in l
145139 close (s1)
146140 close (s2)
147141
148- verbose && println (" $name readuntil..." )
149- @test readuntil (io (), ' \n ' ) == open (io-> readuntil (io,' \n ' ),filename)
150- @test readuntil (io (), " \n " ) == open (io-> readuntil (io," \n " ),filename)
151- @test readuntil (io (), ' ,' ) == open (io-> readuntil (io,' ,' ),filename)
152-
153142 verbose && println (" $name eof..." )
154143 n = length (text) - 1
155144 @test read! (io (), Vector {UInt8} (n)) ==
@@ -170,10 +159,15 @@ for (name, f) in l
170159 UTF8String ([' A' + i % 52 for i in 1 : (div (Base. SZ_UNBUFFERED_IO,2 ))]),
171160 UTF8String ([' A' + i % 52 for i in 1 : ( Base. SZ_UNBUFFERED_IO - 1 )]),
172161 UTF8String ([' A' + i % 52 for i in 1 : ( Base. SZ_UNBUFFERED_IO )]),
173- UTF8String ([' A' + i % 52 for i in 1 : ( Base. SZ_UNBUFFERED_IO + 1 )]),
174- UTF8String ([' A' + i % 52 for i in 1 : (7 + Base. SZ_UNBUFFERED_IO * 3 )])
162+ UTF8String ([' A' + i % 52 for i in 1 : ( Base. SZ_UNBUFFERED_IO + 1 )])
175163 ]
176164
165+ verbose && println (" $name readall..." )
166+ @test readall (io ()) == text
167+
168+ verbose && println (" $name readbytes..." )
169+ @test readbytes (io ()) == Vector {UInt8} (text)
170+
177171 verbose && println (" $name readbytes!..." )
178172 l = length (text)
179173 for n = [1 , 2 , l- 2 , l- 1 , l, l+ 1 , l+ 2 ]
@@ -202,6 +196,11 @@ for (name, f) in l
202196
203197 cleanup ()
204198
199+ verbose && println (" $name readuntil..." )
200+ @test readuntil (io (), ' \n ' ) == readuntil (IOBuffer (text),' \n ' )
201+ @test readuntil (io (), " \n " ) == readuntil (IOBuffer (text)," \n " )
202+ @test readuntil (io (), ' ,' ) == readuntil (IOBuffer (text),' ,' )
203+
205204 verbose && println (" $name readline..." )
206205 @test readline (io ()) == readline (IOBuffer (text))
207206
0 commit comments