31
31
@test repr (ip " 2001:db8:0:0:1:0:0:1" ) == " ip\" 2001:db8::1:0:0:1\" "
32
32
@test repr (ip " 2001:0:0:1:0:0:0:1" ) == " ip\" 2001:0:0:1::1\" "
33
33
34
+ port = RemoteRef ()
34
35
c = Base. Condition ()
35
- port = rand (2000 : 4000 )
36
- @async begin
37
- s = listen (port)
36
+ defaultport = rand (2000 : 4000 )
37
+ tsk = @async begin
38
+ p, s = listenany (defaultport)
39
+ put! (port, p)
38
40
Base. notify (c)
39
41
sock = accept (s)
40
42
write (sock," Hello World\n " )
41
43
close (s)
42
44
close (sock)
43
45
end
44
46
wait (c)
45
- @test readall (connect (port)) == " Hello World\n "
47
+ @test readall (connect (fetch (port))) == " Hello World\n "
48
+ wait (tsk)
46
49
47
- socketname = @windows ? " \\\\ .\\ pipe\\ uv-test" : " testsocket"
50
+ socketname = ( @windows ? " \\\\ .\\ pipe\\ uv-test" : " testsocket" ) * " - " * randstring ( 6 )
48
51
@unix_only isfile (socketname) && Base. FS. unlink (socketname)
49
52
for T in (ASCIIString, UTF8String, UTF16String) # test for issue #9435
50
- @async begin
53
+ tsk = @async begin
51
54
s = listen (T (socketname))
52
55
Base. notify (c)
53
56
sock = accept (s)
@@ -57,21 +60,31 @@ for T in (ASCIIString, UTF8String, UTF16String) # test for issue #9435
57
60
end
58
61
wait (c)
59
62
@test readall (connect (socketname)) == " Hello World\n "
63
+ wait (tsk)
60
64
end
61
65
62
66
@test_throws Base. UVError getaddrinfo (" .invalid" )
63
67
@test_throws Base. UVError connect (" localhost" , 21452 )
64
68
65
- server = listen (port)
66
- @async @test_throws ErrorException accept (server)
67
- sleep (0.1 )
69
+ p, server = listenany (defaultport)
70
+ r = RemoteRef ()
71
+ tsk = @async begin
72
+ put! (r, :start )
73
+ @test_throws Base. UVError accept (server)
74
+ end
75
+ @test fetch (r) === :start
68
76
close (server)
77
+ wait (tsk)
69
78
70
- server = listen (port )
79
+ port, server = listenany (defaultport )
71
80
@async connect (" localhost" ,port)
72
81
s1 = accept (server)
73
82
@test_throws ErrorException accept (server,s1)
83
+ @test_throws Base. UVError listen (port)
84
+ port2, server2 = listenany (port)
85
+ @test port != port2
74
86
close (server)
87
+ close (server2)
75
88
76
89
@test_throws Base. UVError connect (" .invalid" ,80 )
77
90
82
95
bind (b,ip " 127.0.0.1" ,port+ 1 )
83
96
84
97
c = Condition ()
85
- @async begin
98
+ tsk = @async begin
86
99
@test bytestring (recv (a)) == " Hello World"
87
100
# Issue 6505
88
101
@async begin
@@ -93,14 +106,16 @@ begin
93
106
end
94
107
send (b,ip " 127.0.0.1" ,port," Hello World" )
95
108
wait (c)
109
+ wait (tsk)
96
110
97
- @async begin
111
+ tsk = @async begin
98
112
@test begin
99
113
(addr,data) = recvfrom (a)
100
114
addr == ip " 127.0.0.1" && bytestring (data) == " Hello World"
101
115
end
102
116
end
103
117
send (b, ip " 127.0.0.1" ,port," Hello World" )
118
+ wait (tsk)
104
119
105
120
@test_throws MethodError bind (UDPSocket (),port)
106
121
@@ -113,11 +128,12 @@ begin
113
128
bind (a, ip " ::1" , uint16 (port))
114
129
bind (b, ip " ::1" , uint16 (port+ 1 ))
115
130
116
- @async begin
131
+ tsk = @async begin
117
132
@test begin
118
133
(addr, data) = recvfrom (a)
119
134
addr == ip " ::1" && bytestring (data) == " Hello World"
120
135
end
121
136
end
122
137
send (b, ip " ::1" , port, " Hello World" )
138
+ wait (tsk)
123
139
end
0 commit comments