Skip to content

Commit 2b2f24f

Browse files
DilumAluthgetkf
authored andcommitted
Distributed: improve some of the tests in the Distributed test suite when multithreading is enabled (JuliaLang#42499)
Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com> Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com>
1 parent ff180ce commit 2b2f24f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

stdlib/Distributed/test/distributed_exec.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ end
132132
testf(id_me)
133133
testf(id_other)
134134

135+
function poll_while(f::Function; timeout_seconds::Integer = 60)
136+
start_time = time_ns()
137+
while f()
138+
sleep(1)
139+
if ( ( time_ns() - start_time )/1e9 ) > timeout_seconds
140+
@error "Timed out" timeout_seconds
141+
return false
142+
end
143+
end
144+
return true
145+
end
146+
135147
# Distributed GC tests for Futures
136148
function test_futures_dgc(id)
137149
f = remotecall(myid, id)
@@ -143,8 +155,7 @@ function test_futures_dgc(id)
143155
@test fetch(f) == id
144156
@test f.v !== nothing
145157
yield(); # flush gc msgs
146-
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == false
147-
158+
@test poll_while(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))
148159

149160
# if unfetched, it should be deleted after a finalize
150161
f = remotecall(myid, id)
@@ -153,7 +164,7 @@ function test_futures_dgc(id)
153164
@test f.v === nothing
154165
finalize(f)
155166
yield(); # flush gc msgs
156-
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == false
167+
@test poll_while(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))
157168
end
158169

159170
test_futures_dgc(id_me)
@@ -243,7 +254,7 @@ function test_remoteref_dgc(id)
243254
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == true
244255
finalize(rr)
245256
yield(); # flush gc msgs
246-
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == false
257+
@test poll_while(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid))
247258
end
248259
test_remoteref_dgc(id_me)
249260
test_remoteref_dgc(id_other)

0 commit comments

Comments
 (0)