Skip to content

Commit

Permalink
Fix thunk 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 16, 2024
1 parent e1ccbfe commit bf1a4ee
Showing 1 changed file with 13 additions and 14 deletions.
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 bf1a4ee

Please sign in to comment.