Skip to content

Commit 4c8e6c2

Browse files
committed
Improve some of the tests in the Distributed test suite when multithreading is enabled
1 parent f3a847d commit 4c8e6c2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

stdlib/Distributed/test/distributed_exec.jl

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

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

148-
149161
# if unfetched, it should be deleted after a finalize
150162
f = remotecall(myid, id)
151163
fid = remoteref_id(f)
152164
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == true
153165
@test f.v === nothing
154166
finalize(f)
155167
yield(); # flush gc msgs
168+
loop_until_false(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))
156169
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == false
157170
end
158171

@@ -243,6 +256,7 @@ function test_remoteref_dgc(id)
243256
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == true
244257
finalize(rr)
245258
yield(); # flush gc msgs
259+
loop_until_false(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid))
246260
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == false
247261
end
248262
test_remoteref_dgc(id_me)

0 commit comments

Comments
 (0)