From 12209499b08eb126a045b9c39a280c9ebef2bc14 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Mon, 22 Mar 2021 14:14:28 -0400 Subject: [PATCH] fix async test listener Avoid a race condition with connecting before listening, and connect to explicit localhost IP, since the default for `listen` is IPv4, while getaddrinfo for "localhost" may return ip"::1", resulting in connection failure. --- test/async.jl | 70 +++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/test/async.jl b/test/async.jl index 1612a6e..6ccacaf 100644 --- a/test/async.jl +++ b/test/async.jl @@ -1,39 +1,49 @@ +using JSON +using Test +using Distributed: RemoteChannel + +@isdefined(a) || include("json-samples.jl") + finished_async_tests = RemoteChannel() using Sockets -@async begin - s = listen(7777) - s = accept(s) - - Base.start_reading(s) - - @test JSON.parse(s) != nothing # a - @test JSON.parse(s) != nothing # b - validate_c(s) # c - @test JSON.parse(s) != nothing # d - validate_svg_tviewer_menu(s) # svg_tviewer_menu - @test JSON.parse(s) != nothing # gmaps - @test JSON.parse(s) != nothing # colors1 - @test JSON.parse(s) != nothing # colors2 - @test JSON.parse(s) != nothing # colors3 - @test JSON.parse(s) != nothing # twitter - @test JSON.parse(s) != nothing # facebook - validate_flickr(s) # flickr - @test JSON.parse(s) != nothing # youtube - @test JSON.parse(s) != nothing # iphone - @test JSON.parse(s) != nothing # customer - @test JSON.parse(s) != nothing # product - @test JSON.parse(s) != nothing # interop - validate_unicode(s) # unicode - @test JSON.parse(s) != nothing # issue5 - @test JSON.parse(s) != nothing # dollars - @test JSON.parse(s) != nothing # brackets - - put!(finished_async_tests, nothing) +let serv = listen(7777) + @async let s; try + s = accept(serv) + close(serv) + @test JSON.parse(s) != nothing # a + @test JSON.parse(s) != nothing # b + validate_c(s) # c + @test JSON.parse(s) != nothing # d + validate_svg_tviewer_menu(s) # svg_tviewer_menu + @test JSON.parse(s) != nothing # gmaps + @test JSON.parse(s) != nothing # colors1 + @test JSON.parse(s) != nothing # colors2 + @test JSON.parse(s) != nothing # colors3 + @test JSON.parse(s) != nothing # twitter + @test JSON.parse(s) != nothing # facebook + validate_flickr(s) # flickr + @test JSON.parse(s) != nothing # youtube + @test JSON.parse(s) != nothing # iphone + @test JSON.parse(s) != nothing # customer + @test JSON.parse(s) != nothing # product + @test JSON.parse(s) != nothing # interop + validate_unicode(s) # unicode + @test JSON.parse(s) != nothing # issue5 + @test JSON.parse(s) != nothing # dollars + @test JSON.parse(s) != nothing # brackets + + put!(finished_async_tests, nothing) + catch ex + @error "async test failure" _exception=ex + finally + @isdefined(s) && close(s) + close(serv) + end; end end -w = connect("localhost", 7777) +w = connect(Sockets.localhost, 7777) @test JSON.parse(a) != nothing write(w, a)