Skip to content

Commit

Permalink
Distributed: improve some of the tests in the Distributed test suite …
Browse files Browse the repository at this point in the history
…when multithreading is enabled (#42499)

Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com>

Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com>
  • Loading branch information
DilumAluthge and tkf authored Oct 5, 2021
1 parent 2388a5b commit 153db7a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions 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 poll_while(f::Function; timeout_seconds::Integer = 60)
start_time = time_ns()
while f()
sleep(1)
if ( ( time_ns() - start_time )/1e9 ) > timeout_seconds
@error "Timed out" timeout_seconds
return false
end
end
return true
end

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

@test poll_while(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, fid))

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

test_futures_dgc(id_me)
Expand Down Expand Up @@ -243,7 +254,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
@test remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid) == false
@test poll_while(() -> remotecall_fetch(k->(yield();haskey(Distributed.PGRP.refs, k)), id, rrid))
end
test_remoteref_dgc(id_me)
test_remoteref_dgc(id_other)
Expand Down

0 comments on commit 153db7a

Please sign in to comment.