From c7e2f9b4884b9f4177be4a0fd743c7667e36d3e2 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 15 Jul 2022 10:46:48 -0700 Subject: [PATCH] Close race condition in Filewatching tests (#46028) On some machines, we are able to delay starting our loop until more than a second after we take the lock, which of course breaks the test. Let's use a synchronization barrier to ensure that we're testing what we intend to. --- stdlib/FileWatching/test/pidfile.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/FileWatching/test/pidfile.jl b/stdlib/FileWatching/test/pidfile.jl index febc082518edf..fae745131bca3 100644 --- a/stdlib/FileWatching/test/pidfile.jl +++ b/stdlib/FileWatching/test/pidfile.jl @@ -272,7 +272,9 @@ end # Just for coverage's sake, run a test with do-block syntax lock_times = Float64[] + synchronizer = Base.Event() t_loop = @async begin + wait(synchronizer) for idx in 1:100 t = @elapsed mkpidlock("do_block_pidfile") do # nothing @@ -283,6 +285,7 @@ end end isdefined(Base, :errormonitor) && Base.errormonitor(t_loop) mkpidlock("do_block_pidfile") do + notify(synchronizer) sleep(3) end wait(t_loop)