From f3467350080cb7925e8f70027c30588af66e523d Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 29 Sep 2022 20:52:37 +0200 Subject: [PATCH] avoid timing race in async test (#46941) This is the test from #27164. The test was checking whether sleep(1) (which is started first) or sleep(0.05) (which is nominally shorter) returned first. Use an Event instead so that they are explicitly ordered. Fixes #46360 --- test/misc.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/misc.jl b/test/misc.jl index 8a0ad13403bcd..75055f62c4968 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -237,14 +237,16 @@ end # test that @sync is lexical (PR #27164) const x27164 = Ref(0) -do_something_async_27164() = @async(begin sleep(1); x27164[] = 2; end) +const c27164 = Base.Event() +do_something_async_27164() = @async(begin wait(c27164); x27164[] = 2; end) let t = nothing @sync begin + @async (sleep(0.1); x27164[] = 1) t = do_something_async_27164() - @async (sleep(0.05); x27164[] = 1) end @test x27164[] == 1 + notify(c27164) fetch(t) @test x27164[] == 2 end