Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,13 @@ this section verbatim). Each entry is one bullet starting with `- `.
A launcher can therefore be instrumented while the extension exercised by
every rank reports zero hits. Forward the enabled mode/path and merge the
PID-qualified rank reports.

113. **Threaded test RPCs need ready peer connections.** Julia 1.11's stdlib
`Distributed` creates its lazy peer condition on the worker's initial
thread; the first peer RPC from another thread can throw `lock must be
held`. Start test workers with the supported `lazy=false` option and
exercise their first peer RPC before other tests warm it. This configures
the fixture; the cold lazy path remains an upstream stdlib issue, and
production transport defaults must stay unchanged. Every test worker addition
must use the same setting: both transports reject mixing lazy and eager
workers in one cluster.
8 changes: 4 additions & 4 deletions test/fault-tolerance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
d = delayed(kill_func)(b, c)
@test collect(d) == 6

addprocs(2)
add_test_workers(Distributed, 2)
using Dagger
setup_funcs(workers() |> last)

Expand All @@ -44,7 +44,7 @@
c = delayed(kill_func)(a, b)
@test collect(c) == 6

addprocs(2)
add_test_workers(Distributed, 2)
using Dagger
setup_funcs(workers() |> last)

Expand All @@ -56,7 +56,7 @@
c = delayed(kill_func)(b1, b2)
@test collect(c) == 8

addprocs(2)
add_test_workers(Distributed, 2)
using Dagger
setup_funcs(workers() |> last)

Expand All @@ -66,7 +66,7 @@
d = delayed(kill_func)(b, c)
@test_throws AssertionError collect(d; options=Dagger.Sch.SchedulerOptions(single=first(workers())))

addprocs(1)
add_test_workers(Distributed, 1)
using Dagger
setup_funcs(workers() |> last)
end
Expand Down
27 changes: 18 additions & 9 deletions test/processors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,27 @@ end
end

@testset "Modify workers in Context" begin
ps = addprocs(4, exeflags=`--project=$(Base.active_project())`)
@everywhere ps using Dagger
ps = add_test_workers(Distributed, 4; threads=2)
try
# The first worker-to-worker RPC must be safe from another thread,
# before Dagger loading or an earlier call can warm that connection.
@everywhere ps include($(joinpath(@__DIR__, "worker_setup.jl")))
first_peer = remotecall_fetch(threaded_test_peer, ps[1], Distributed, ps[2])
@test first_peer.value == 7
@test first_peer.rpc_tid == last(first_peer.default_tids)
@test first_peer.rpc_tid != first_peer.entry_tid
@everywhere ps using Dagger

ctx = Context(ps[1:2])
ctx = Context(ps[1:2])

Dagger.addprocs!(ctx, ps[3:end])
@test map(p -> p.pid, procs(ctx)) == ps
Dagger.addprocs!(ctx, ps[3:end])
@test map(p -> p.pid, procs(ctx)) == ps

Dagger.rmprocs!(ctx, ps[3:end])
@test map(p -> p.pid, procs(ctx)) == ps[1:2]

wait(rmprocs(ps))
Dagger.rmprocs!(ctx, ps[3:end])
@test map(p -> p.pid, procs(ctx)) == ps[1:2]
finally
wait(rmprocs(ps))
end
end

@testset "Callable as Thunk function" begin
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@ end
using Dagger
const Distributed = parentmodule(Dagger.myid)
using .Distributed
include("worker_setup.jl")
if additional_workers > 0
# We put this inside a branch because addprocs() takes a minimum of 1s to
# complete even if doing nothing, which is annoying.
# Pkg.test runs in a temporary project containing the test-only backends.
# Workers must use that same resolution, rather than the repository project.
addprocs(additional_workers; exeflags=`--project=$(Base.active_project()) -t $worker_threads`)
add_test_workers(Distributed, additional_workers; threads=worker_threads)
end

include("imports.jl")
Expand Down
2 changes: 1 addition & 1 deletion test/scheduler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ end
@testset "Remove all workers throws" begin
ps = []
try
ps1 = addprocs(2, exeflags=`--project=$(Base.active_project())`)
ps1 = add_test_workers(Distributed, 2)
append!(ps, ps1)

@everywhere vcat(ps1, myid()) $setup
Expand Down
2 changes: 1 addition & 1 deletion test/scopes.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "Chunk Scopes" begin
wid1, wid2 = addprocs(2, exeflags=["-t2", "--project=$(Base.active_project())"])
wid1, wid2 = add_test_workers(Distributed, 2; threads=2)
@everywhere [wid1,wid2] using Dagger
Dagger.addprocs!(Dagger.Sch.eager_context(), [wid1,wid2])
fetch(Dagger.@spawn 1+1) # Force scheduler to pick up new workers
Expand Down
25 changes: 25 additions & 0 deletions test/worker_setup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test workers must have their peer connections before a test issues RPCs from
# another thread. Julia 1.11's stdlib lazy connection condition is thread-affine;
# eager setup avoids that cold wait without changing production defaults.
function add_test_workers(transport::Module, count::Integer;
project=Base.active_project(), threads::Integer=1)
return transport.addprocs(count; lazy=false,
exeflags=`--project=$project -t $threads`)
end

# Invoke the first peer RPC on a different thread from the worker's RPC entry
# task. This uses only public transport/thread APIs and does not load Dagger.
function threaded_test_peer(transport::Module, target::Integer)
@assert Threads.nthreads() >= 2
entry_tid = Threads.threadid()
rpc_tid = Ref(0)
value = Ref(0)
Threads.@threads :static for i in 1:Threads.nthreads()
if i == Threads.nthreads()
rpc_tid[] = Threads.threadid()
value[] = transport.remotecall_fetch(identity, target, 7)
end
end
return (; entry_tid, rpc_tid=rpc_tid[], value=value[],
default_tids=collect(Threads.threadpooltids(:default)))
end
Loading