Skip to content

Commit 063477d

Browse files
committed
Revert "test: replcompletions: Replace timedwait by proper condvar (#58643)"
This reverts commit aa56078.
1 parent 96423ba commit 063477d

File tree

2 files changed

+15
-44
lines changed

2 files changed

+15
-44
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ end
330330

331331
const PATH_cache_lock = Base.ReentrantLock()
332332
const PATH_cache = Set{String}()
333-
PATH_cache_task::Union{Task,Nothing} = nothing
334-
PATH_cache_condition::Union{Threads.Condition, Nothing} = nothing # used for sync in tests
333+
PATH_cache_task::Union{Task,Nothing} = nothing # used for sync in tests
335334
next_cache_update::Float64 = 0.0
336335
function maybe_spawn_cache_PATH()
337336
global PATH_cache_task, next_cache_update
@@ -340,11 +339,7 @@ function maybe_spawn_cache_PATH()
340339
time() < next_cache_update && return
341340
PATH_cache_task = Threads.@spawn begin
342341
REPLCompletions.cache_PATH()
343-
@lock PATH_cache_lock begin
344-
next_cache_update = time() + 10 # earliest next update can run is 10s after
345-
PATH_cache_task = nothing # release memory when done
346-
PATH_cache_condition !== nothing && notify(PATH_cache_condition)
347-
end
342+
@lock PATH_cache_lock PATH_cache_task = nothing # release memory when done
348343
end
349344
Base.errormonitor(PATH_cache_task)
350345
end
@@ -355,6 +350,8 @@ function cache_PATH()
355350
path = get(ENV, "PATH", nothing)
356351
path isa String || return
357352

353+
global next_cache_update
354+
358355
# Calling empty! on PATH_cache would be annoying for async typing hints as completions would temporarily disappear.
359356
# So keep track of what's added this time and at the end remove any that didn't appear this time from the global cache.
360357
this_PATH_cache = Set{String}()
@@ -417,6 +414,7 @@ function cache_PATH()
417414

418415
@lock PATH_cache_lock begin
419416
intersect!(PATH_cache, this_PATH_cache) # remove entries from PATH_cache that weren't found this time
417+
next_cache_update = time() + 10 # earliest next update can run is 10s after
420418
end
421419

422420
@debug "caching PATH files took $t seconds" length(pathdirs) length(PATH_cache)

stdlib/REPL/test/replcompletions.jl

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,39 +1073,6 @@ let c, r, res
10731073
@test res === false
10741074
end
10751075

1076-
# A pair of utility function for the REPL completions test to test PATH_cache
1077-
# dependent completions, which ordinarily happen asynchronously.
1078-
# Only to be used from the test suite
1079-
function test_only_arm_cache_refresh()
1080-
@lock REPL.REPLCompletions.PATH_cache_lock begin
1081-
@assert REPL.REPLCompletions.PATH_cache_condition === nothing
1082-
1083-
# Arm a condition we can wait on
1084-
REPL.REPLCompletions.PATH_cache_condition = Threads.Condition(REPL.REPLCompletions.PATH_cache_lock)
1085-
1086-
# Check if the previous update is still running - if so, wait for it to finish
1087-
while REPL.REPLCompletions.PATH_cache_task !== nothing
1088-
@assert !istaskdone(REPL.REPLCompletions.PATH_cache_task)
1089-
wait(REPL.REPLCompletions.PATH_cache_condition)
1090-
end
1091-
1092-
# force the next cache update to happen immediately
1093-
REPL.REPLCompletions.next_cache_update = 0
1094-
end
1095-
return REPL.REPLCompletions.PATH_cache_condition
1096-
end
1097-
1098-
function test_only_wait_cache_path_done()
1099-
@lock REPL.REPLCompletions.PATH_cache_lock begin
1100-
@assert REPL.REPLCompletions.PATH_cache_condition !== nothing
1101-
1102-
while REPL.REPLCompletions.next_cache_update == 0.
1103-
wait(REPL.REPLCompletions.PATH_cache_condition)
1104-
end
1105-
REPL.REPLCompletions.PATH_cache_condition = nothing
1106-
end
1107-
end
1108-
11091076
if Sys.isunix()
11101077
let s, c, r
11111078
#Assume that we can rely on the existence and accessibility of /tmp
@@ -1237,9 +1204,12 @@ let s, c, r
12371204
# Files reachable by PATH are cached async when PATH is seen to have been changed by `complete_path`
12381205
# so changes are unlikely to appear in the first complete. For testing purposes we can wait for
12391206
# caching to finish
1240-
test_only_arm_cache_refresh()
1207+
@lock REPL.REPLCompletions.PATH_cache_lock begin
1208+
# force the next cache update to happen immediately
1209+
REPL.REPLCompletions.next_cache_update = 0
1210+
end
12411211
c,r = test_scomplete(s)
1242-
test_only_wait_cache_path_done()
1212+
timedwait(()->REPL.REPLCompletions.next_cache_update != 0, 5) # wait for caching to complete
12431213
c,r = test_scomplete(s)
12441214
@test "tmp-executable" in c
12451215
@test r == 1:9
@@ -1268,9 +1238,12 @@ let s, c, r
12681238

12691239
withenv("PATH" => string(tempdir(), ":", dir)) do
12701240
s = string("repl-completio")
1271-
test_only_arm_cache_refresh()
1241+
@lock REPL.REPLCompletions.PATH_cache_lock begin
1242+
# force the next cache update to happen immediately
1243+
REPL.REPLCompletions.next_cache_update = 0
1244+
end
12721245
c,r = test_scomplete(s)
1273-
test_only_wait_cache_path_done()
1246+
timedwait(()->REPL.REPLCompletions.next_cache_update != 0, 5) # wait for caching to complete
12741247
c,r = test_scomplete(s)
12751248
@test ["repl-completion"] == c
12761249
@test s[r] == "repl-completio"

0 commit comments

Comments
 (0)