Skip to content

Commit 60836ac

Browse files
authored
Use listenany for async tests; fixes #349 (#350)
1 parent de16550 commit 60836ac

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

test/async.jl

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,97 @@
11
using JSON
22
using Test
33
using Distributed: RemoteChannel
4+
using Sockets
45

56
@isdefined(a) || include("json-samples.jl")
67

78
finished_async_tests = RemoteChannel()
89

9-
using Sockets
10-
11-
let serv = listen(7777)
12-
@async let s; try
13-
s = accept(serv)
14-
close(serv)
15-
@test JSON.parse(s) != nothing # a
16-
@test JSON.parse(s) != nothing # b
17-
validate_c(s) # c
18-
@test JSON.parse(s) != nothing # d
19-
validate_svg_tviewer_menu(s) # svg_tviewer_menu
20-
@test JSON.parse(s) != nothing # gmaps
21-
@test JSON.parse(s) != nothing # colors1
22-
@test JSON.parse(s) != nothing # colors2
23-
@test JSON.parse(s) != nothing # colors3
24-
@test JSON.parse(s) != nothing # twitter
25-
@test JSON.parse(s) != nothing # facebook
26-
validate_flickr(s) # flickr
27-
@test JSON.parse(s) != nothing # youtube
28-
@test JSON.parse(s) != nothing # iphone
29-
@test JSON.parse(s) != nothing # customer
30-
@test JSON.parse(s) != nothing # product
31-
@test JSON.parse(s) != nothing # interop
32-
validate_unicode(s) # unicode
33-
@test JSON.parse(s) != nothing # issue5
34-
@test JSON.parse(s) != nothing # dollars
35-
@test JSON.parse(s) != nothing # brackets
36-
37-
put!(finished_async_tests, nothing)
38-
catch ex
39-
@error "async test failure" _exception=ex
40-
finally
41-
@isdefined(s) && close(s)
42-
close(serv)
43-
end; end
44-
end
45-
46-
w = connect(Sockets.localhost, 7777)
47-
48-
@test JSON.parse(a) != nothing
10+
port, serv = listenany(7777)
11+
@async let s; try
12+
s = accept(serv)
13+
close(serv)
14+
@test JSON.parse(s) !== nothing # a
15+
@test JSON.parse(s) !== nothing # b
16+
validate_c(s) # c
17+
@test JSON.parse(s) !== nothing # d
18+
validate_svg_tviewer_menu(s) # svg_tviewer_menu
19+
@test JSON.parse(s) !== nothing # gmaps
20+
@test JSON.parse(s) !== nothing # colors1
21+
@test JSON.parse(s) !== nothing # colors2
22+
@test JSON.parse(s) !== nothing # colors3
23+
@test JSON.parse(s) !== nothing # twitter
24+
@test JSON.parse(s) !== nothing # facebook
25+
validate_flickr(s) # flickr
26+
@test JSON.parse(s) !== nothing # youtube
27+
@test JSON.parse(s) !== nothing # iphone
28+
@test JSON.parse(s) !== nothing # customer
29+
@test JSON.parse(s) !== nothing # product
30+
@test JSON.parse(s) !== nothing # interop
31+
validate_unicode(s) # unicode
32+
@test JSON.parse(s) !== nothing # issue5
33+
@test JSON.parse(s) !== nothing # dollars
34+
@test JSON.parse(s) !== nothing # brackets
35+
36+
put!(finished_async_tests, nothing)
37+
catch ex
38+
@error "async test failure" _exception=ex
39+
finally
40+
@isdefined(s) && close(s)
41+
close(serv)
42+
end; end
43+
44+
w = connect(Sockets.localhost, port)
45+
46+
@test JSON.parse(a) !== nothing
4947
write(w, a)
5048

51-
@test JSON.parse(b) != nothing
49+
@test JSON.parse(b) !== nothing
5250
write(w, b)
5351

5452
validate_c(c)
5553
write(w, c)
5654

57-
@test JSON.parse(d) != nothing
55+
@test JSON.parse(d) !== nothing
5856
write(w, d)
5957

6058
validate_svg_tviewer_menu(svg_tviewer_menu)
6159
write(w, svg_tviewer_menu)
6260

63-
@test JSON.parse(gmaps) != nothing
61+
@test JSON.parse(gmaps) !== nothing
6462
write(w, gmaps)
6563

66-
@test JSON.parse(colors1) != nothing
64+
@test JSON.parse(colors1) !== nothing
6765
write(w, colors1)
6866

69-
@test JSON.parse(colors2) != nothing
67+
@test JSON.parse(colors2) !== nothing
7068
write(w, colors2)
7169

72-
@test JSON.parse(colors3) != nothing
70+
@test JSON.parse(colors3) !== nothing
7371
write(w, colors3)
7472

75-
@test JSON.parse(twitter) != nothing
73+
@test JSON.parse(twitter) !== nothing
7674
write(w, twitter)
7775

78-
@test JSON.parse(facebook) != nothing
76+
@test JSON.parse(facebook) !== nothing
7977
write(w, facebook)
8078

8179
validate_flickr(flickr)
8280
write(w, flickr)
8381

84-
@test JSON.parse(youtube) != nothing
82+
@test JSON.parse(youtube) !== nothing
8583
write(w, youtube)
8684

87-
@test JSON.parse(iphone) != nothing
85+
@test JSON.parse(iphone) !== nothing
8886
write(w, iphone)
8987

90-
@test JSON.parse(customer) != nothing
88+
@test JSON.parse(customer) !== nothing
9189
write(w, customer)
9290

93-
@test JSON.parse(product) != nothing
91+
@test JSON.parse(product) !== nothing
9492
write(w, product)
9593

96-
@test JSON.parse(interop) != nothing
94+
@test JSON.parse(interop) !== nothing
9795
write(w, interop)
9896

9997
validate_unicode(unicode)
@@ -107,13 +105,13 @@ write(w, issue5)
107105
# $ escaping issue
108106
dollars = ["all of the \$s", "µniçø∂\$"]
109107
json_dollars = json(dollars)
110-
@test JSON.parse(json_dollars) != nothing
108+
@test JSON.parse(json_dollars) !== nothing
111109
write(w, json_dollars)
112110

113111
# unmatched brackets
114112
brackets = Dict("foo"=>"ba}r", "be}e]p"=>"boo{p")
115113
json_brackets = json(brackets)
116-
@test JSON.parse(json_brackets) != nothing
114+
@test JSON.parse(json_brackets) !== nothing
117115
write(w, json_dollars)
118116

119117
fetch(finished_async_tests)

0 commit comments

Comments
 (0)