Skip to content

Commit 872d8ea

Browse files
vtjnashJeffBezanson
authored andcommitted
FileWatching,test: remove max timeout (#33316)
This has been pretty flaky on CI systems, and isn't really required of the tests. fix #33311
1 parent d06cefa commit 872d8ea

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

stdlib/FileWatching/src/FileWatching.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ function watch_folder(s::String, timeout_s::Real=-1)
719719
end
720720
if timeout_s >= 0 && !isready(fm.notify)
721721
if timeout_s <= 0.010
722-
# for very small timeouts, we can just sleep for the timeout-interval
722+
# for very small timeouts, we can just sleep for the whole timeout-interval
723723
(timeout_s == 0) ? yield() : sleep(timeout_s)
724724
if !isready(fm.notify)
725725
return "" => FileEvent() # timeout

stdlib/FileWatching/test/runtests.jl

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,15 @@ end
3030
function pfd_tst_reads(idx, intvl)
3131
global ready += 1
3232
wait(ready_c)
33-
t_elapsed = @elapsed begin
34-
start_evt2 = Condition()
35-
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
36-
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
37-
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
38-
end
33+
start_evt2 = Condition()
34+
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
35+
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
36+
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
3937
@test !evt.timedout
4038
@test evt.readable
4139
@test !evt.writable
4240
@test evt === fetch(evt2)
4341

44-
# println("Expected ", intvl, ", actual ", t_elapsed, ", diff ", t_elapsed - intvl)
45-
# Disabled since this assertion fails randomly, notably on build VMs (issue #12824)
46-
# @test t_elapsed <= (intvl + 1)
47-
4842
dout = zeros(UInt8, 1)
4943
@static if Sys.iswindows()
5044
1 == ccall(:recv, stdcall, Cint, (Ptr{Cvoid}, Ptr{UInt8}, Cint, Cint), pipe_fds[idx][1], dout, 1, 0) || error(Libc.FormatMessage())
@@ -58,23 +52,16 @@ end
5852
function pfd_tst_timeout(idx, intvl)
5953
global ready += 1
6054
wait(ready_c)
61-
t_elapsed = @elapsed begin
62-
start_evt2 = Condition()
63-
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
64-
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
65-
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
66-
@test evt.timedout
67-
@test !evt.readable
68-
@test !evt.writable
69-
@test evt === fetch(evt2)
70-
end
71-
72-
# Disabled since these assertions fail randomly, notably on build VMs (issue #12824)
73-
# @test intvl <= t_elapsed
74-
# @test t_elapsed <= (intvl + 1)
55+
start_evt2 = Condition()
56+
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
57+
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
58+
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
59+
@test evt.timedout
60+
@test !evt.readable
61+
@test !evt.writable
62+
@test evt === fetch(evt2)
7563
end
7664

77-
7865
# Odd numbers trigger reads, even numbers timeout
7966
for (i, intvl) in enumerate(intvls)
8067
@sync begin
@@ -176,24 +163,24 @@ file = joinpath(dir, "afile.txt")
176163
# initialize a watch_folder instance and create afile.txt
177164
function test_init_afile()
178165
@test isempty(FileWatching.watched_folders)
179-
@test @elapsed(@test(watch_folder(dir, 0) == ("" => FileWatching.FileEvent()))) <= 2
166+
@test(watch_folder(dir, 0) == ("" => FileWatching.FileEvent()))
180167
@test @elapsed(@test(watch_folder(dir, 0) == ("" => FileWatching.FileEvent()))) <= 0.5
181168
@test length(FileWatching.watched_folders) == 1
182169
@test unwatch_folder(dir) === nothing
183170
@test isempty(FileWatching.watched_folders)
184-
@test 0.001 <= @elapsed(@test(watch_folder(dir, 0.004) == ("" => FileWatching.FileEvent()))) <= 2
185-
@test 0.001 <= @elapsed(@test(watch_folder(dir, 0.004) == ("" => FileWatching.FileEvent()))) <= 0.5
171+
@test 0.002 <= @elapsed(@test(watch_folder(dir, 0.004) == ("" => FileWatching.FileEvent())))
172+
@test 0.002 <= @elapsed(@test(watch_folder(dir, 0.004) == ("" => FileWatching.FileEvent()))) <= 0.5
186173
@test unwatch_folder(dir) === nothing
187-
@test 0.9 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent()))) <= 4
188-
@test 0.9 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent()))) <= 1.5
174+
@test 0.99 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent())))
175+
@test 0.99 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent())))
189176
# like touch, but lets the operating system update the timestamp
190177
# for greater precision on some platforms (windows)
191178
@test close(open(file, "w")) === nothing
192-
@test @elapsed(@test(watch_folder(dir) == (F_PATH => FileWatching.FileEvent(FileWatching.UV_RENAME)))) <= 0.5
179+
@test(watch_folder(dir) == (F_PATH => FileWatching.FileEvent(FileWatching.UV_RENAME)))
193180
@test close(open(file, "w")) === nothing
194181
sleep(3)
195182
let c
196-
@test @elapsed(c = watch_folder(dir, 0)) <= 0.5
183+
c = watch_folder(dir, 0)
197184
if F_GETPATH
198185
@test c.first == F_PATH
199186
@test c.second.changed c.second.renamed
@@ -205,8 +192,8 @@ function test_init_afile()
205192
end
206193
end
207194
@test unwatch_folder(dir) === nothing
208-
@test @elapsed(@test(watch_folder(dir, 0) == ("" => FileWatching.FileEvent()))) <= 0.5
209-
@test 0.9 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent()))) <= 1.5
195+
@test(watch_folder(dir, 0) == ("" => FileWatching.FileEvent()))
196+
@test 0.9 <= @elapsed(@test(watch_folder(dir, 1) == ("" => FileWatching.FileEvent())))
210197
@test length(FileWatching.watched_folders) == 1
211198
nothing
212199
end
@@ -384,8 +371,8 @@ mv(file * "~", file)
384371
let changes = []
385372
while true
386373
let c
387-
timeout = Sys.iswindows() ? 0.1 : 0.0
388-
@test @elapsed(c = watch_folder(dir, timeout)) < 0.5
374+
Sys.iswindows() && sleep(0.1)
375+
@test @elapsed(c = watch_folder(dir, 0.0)) < 0.5
389376
push!(changes, c)
390377
(c.second::FileWatching.FileEvent).timedout && break
391378
end

0 commit comments

Comments
 (0)