Skip to content

Commit

Permalink
avoid timing race in async test (#46941)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vtjnash authored Sep 29, 2022
1 parent 6863249 commit f346735
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f346735

Please sign in to comment.