Skip to content

Commit

Permalink
Fix @test_throws_unwrap tests
Browse files Browse the repository at this point in the history
`unwrap_nested_exception()` now supports `DTaskFailedException` so we can match
against the real exceptions thrown.
  • Loading branch information
JamesWrigley committed Nov 17, 2024
1 parent 079e9fa commit 999bdd7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
4 changes: 3 additions & 1 deletion test/mutation.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Dagger.Sch: SchedulingException

@everywhere begin
struct DynamicHistogram
bins::Vector{Float64}
Expand Down Expand Up @@ -48,7 +50,7 @@ end
x = Dagger.@mutable worker=w Ref{Int}()
@test fetch(Dagger.@spawn mutable_update!(x)) == w
wo_scope = Dagger.ProcessScope(wo)
@test_throws_unwrap Dagger.DTaskFailedException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
@test_throws_unwrap SchedulingException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
end
end # @testset "@mutable"

Expand Down
6 changes: 3 additions & 3 deletions test/processors.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Distributed
import Dagger: Context, Processor, OSProc, ThreadProc, get_parent, get_processors
import Dagger.Sch: ThunkOptions
import Dagger.Sch: ThunkOptions, SchedulingException

@everywhere begin

Expand Down Expand Up @@ -37,9 +37,9 @@ end
end
@testset "Processor exhaustion" begin
opts = ThunkOptions(proclist=[OptOutProc])
@test_throws_unwrap Dagger.DTaskFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
@test_throws_unwrap SchedulingException reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
opts = ThunkOptions(proclist=(proc)->false)
@test_throws_unwrap Dagger.DTaskFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
@test_throws_unwrap SchedulingException reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
opts = ThunkOptions(proclist=nothing)
@test collect(delayed(sum; options=opts)([1,2,3])) == 6
end
Expand Down
6 changes: 3 additions & 3 deletions test/scheduler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ end
@testset "allow errors" begin
opts = ThunkOptions(;allow_errors=true)
a = delayed(error; options=opts)("Test")
@test_throws_unwrap Dagger.DTaskFailedException collect(a)
@test_throws_unwrap ErrorException collect(a)
end
end

Expand Down Expand Up @@ -396,7 +396,7 @@ end
([Dagger.tochunk(MyStruct(1)), Dagger.tochunk(1)], sizeof(MyStruct)+sizeof(Int)),
]
for arg in args
if arg isa Chunk
if arg isa Dagger.Chunk
aff = Dagger.affinity(arg)
@test aff[1] == OSProc(1)
@test aff[2] == MemPool.approx_size(MemPool.poolget(arg.handle))
Expand Down Expand Up @@ -540,7 +540,7 @@ end
t = Dagger.@spawn scope=Dagger.scope(worker=1, thread=1) sleep(100)
start_time = time_ns()
Dagger.cancel!(t)
@test_throws_unwrap Dagger.DTaskFailedException fetch(t)
@test_throws_unwrap InterruptException fetch(t)
t = Dagger.@spawn scope=Dagger.scope(worker=1, thread=1) yield()
fetch(t)
finish_time = time_ns()
Expand Down
12 changes: 7 additions & 5 deletions test/scopes.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Dagger.Sch: SchedulingException

@testset "Chunk Scopes" begin
wid1, wid2 = addprocs(2, exeflags=["-t 2"])
@everywhere [wid1,wid2] using Dagger
Expand Down Expand Up @@ -56,7 +58,7 @@

# Different nodes
for (ch1, ch2) in [(ns1_ch, ns2_ch), (ns2_ch, ns1_ch)]
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
end
end
@testset "Process Scope" begin
Expand All @@ -75,15 +77,15 @@

# Different process
for (ch1, ch2) in [(ps1_ch, ps2_ch), (ps2_ch, ps1_ch)]
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
end

# Same process and node
@test fetch(Dagger.@spawn process_scope_test(ps1_ch, ns1_ch)) == wid1

# Different process and node
for (ch1, ch2) in [(ps1_ch, ns2_ch), (ns2_ch, ps1_ch)]
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
end
end
@testset "Exact Scope" begin
Expand All @@ -104,14 +106,14 @@

# Different process, different processor
for (ch1, ch2) in [(es1_ch, es2_ch), (es2_ch, es1_ch)]
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
end

# Same process, different processor
es1_2 = ExactScope(Dagger.ThreadProc(wid1, 2))
es1_2_ch = Dagger.tochunk(nothing, OSProc(), es1_2)
for (ch1, ch2) in [(es1_ch, es1_2_ch), (es1_2_ch, es1_ch)]
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
end
end
@testset "Union Scope" begin
Expand Down
27 changes: 13 additions & 14 deletions test/thunk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end
A = rand(4, 4)
@test fetch(@spawn sum(A; dims=1)) sum(A; dims=1)

@test_throws_unwrap Dagger.DTaskFailedException fetch(@spawn sum(A; fakearg=2))
@test_throws_unwrap MethodError fetch(@spawn sum(A; fakearg=2))

@test fetch(@spawn reduce(+, A; dims=1, init=2.0))
reduce(+, A; dims=1, init=2.0)
Expand Down Expand Up @@ -194,7 +194,7 @@ end
a = @spawn error("Test")
wait(a)
@test isready(a)
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
@test_throws_unwrap ErrorException fetch(a)
b = @spawn 1+2
@test fetch(b) == 3
end
Expand All @@ -207,7 +207,6 @@ end
catch err
err
end
ex = Dagger.Sch.unwrap_nested_exception(ex)
ex_str = sprint(io->Base.showerror(io,ex))
@test occursin(r"^DTaskFailedException:", ex_str)
@test occursin("Test", ex_str)
Expand All @@ -218,44 +217,43 @@ end
catch err
err
end
ex = Dagger.Sch.unwrap_nested_exception(ex)
ex_str = sprint(io->Base.showerror(io,ex))
@test occursin("Test", ex_str)
@test occursin("Root Task", ex_str)
end
@testset "single dependent" begin
a = @spawn error("Test")
b = @spawn a+2
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
@test_throws_unwrap ErrorException fetch(a)
end
@testset "multi dependent" begin
a = @spawn error("Test")
b = @spawn a+2
c = @spawn a*2
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
@test_throws_unwrap ErrorException fetch(b)
@test_throws_unwrap ErrorException fetch(c)
end
@testset "dependent chain" begin
a = @spawn error("Test")
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
@test_throws_unwrap ErrorException fetch(a)
b = @spawn a+1
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
@test_throws_unwrap ErrorException fetch(b)
c = @spawn b+2
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
@test_throws_unwrap ErrorException fetch(c)
end
@testset "single input" begin
a = @spawn 1+1
b = @spawn (a->error("Test"))(a)
@test fetch(a) == 2
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
@test_throws_unwrap ErrorException fetch(b)
end
@testset "multi input" begin
a = @spawn 1+1
b = @spawn 2*2
c = @spawn ((a,b)->error("Test"))(a,b)
@test fetch(a) == 2
@test fetch(b) == 4
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
@test_throws_unwrap ErrorException fetch(c)
end
@testset "diamond" begin
a = @spawn 1+1
Expand All @@ -265,9 +263,10 @@ end
@test fetch(a) == 2
@test fetch(b) == 3
@test fetch(c) == 4
@test_throws_unwrap Dagger.DTaskFailedException fetch(d)
@test_throws_unwrap ErrorException fetch(d)
end
end

@testset "remote spawn" begin
a = fetch(Distributed.@spawnat 2 Dagger.@spawn 1+2)
@test Dagger.Sch.EAGER_INIT[]
Expand All @@ -283,7 +282,7 @@ end
t1 = Dagger.@spawn 1+"fail"
Dagger.@spawn t1+1
end
@test_throws_unwrap Dagger.DTaskFailedException fetch(t2)
@test_throws_unwrap MethodError fetch(t2)
end
@testset "undefined function" begin
# Issues #254, #255
Expand Down

0 comments on commit 999bdd7

Please sign in to comment.