Skip to content

Commit

Permalink
Improve some of the tests in the Distributed test suite when multithr…
Browse files Browse the repository at this point in the history
…eading is enabled
  • Loading branch information
DilumAluthge committed Oct 5, 2021
1 parent f3a847d commit 4c8e6c2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ end
testf(id_me)
testf(id_other)

function loop_until_false(f::Function; timeout_seconds::Integer = 60)
start_time = time_ns()
while f() != false
sleep(1)
if ( ( time_ns() - start_time )/1e9 ) > timeout_seconds
@error "Timed out" timeout_seconds
return nothing
end
end
return nothing
end

# Distributed GC tests for Futures
function test_futures_dgc(id)
f = remotecall(myid, id)
Expand All @@ -143,16 +155,17 @@ function test_futures_dgc(id)
@test fetch(f) == id
@test f.v !== nothing
yield(); # flush gc msgs
loop_until_false(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == false


# if unfetched, it should be deleted after a finalize
f = remotecall(myid, id)
fid = remoteref_id(f)
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == true
@test f.v === nothing
finalize(f)
yield(); # flush gc msgs
loop_until_false(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid) == false
end

Expand Down Expand Up @@ -243,6 +256,7 @@ function test_remoteref_dgc(id)
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == true
finalize(rr)
yield(); # flush gc msgs
loop_until_false(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid))
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == false
end
test_remoteref_dgc(id_me)
Expand Down

0 comments on commit 4c8e6c2

Please sign in to comment.