Skip to content

Commit e6f2305

Browse files
committed
tests: Test DTaskFailedException inner type
1 parent 4d4047e commit e6f2305

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

test/processors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ end
3737
end
3838
@testset "Processor exhaustion" begin
3939
opts = ThunkOptions(proclist=[OptOutProc])
40-
@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]))
40+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
4141
opts = ThunkOptions(proclist=(proc)->false)
42-
@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]))
42+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
4343
opts = ThunkOptions(proclist=nothing)
4444
@test collect(delayed(sum; options=opts)([1,2,3])) == 6
4545
end

test/thunk.jl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969
A = rand(4, 4)
7070
@test fetch(@spawn sum(A; dims=1)) sum(A; dims=1)
7171

72-
@test_throws_unwrap Dagger.DTaskFailedException fetch(@spawn sum(A; fakearg=2))
72+
@test_throws_unwrap (Dagger.DTaskFailedException, MethodError) fetch(@spawn sum(A; fakearg=2))
7373

7474
@test fetch(@spawn reduce(+, A; dims=1, init=2.0))
7575
reduce(+, A; dims=1, init=2.0)
@@ -194,7 +194,7 @@ end
194194
a = @spawn error("Test")
195195
wait(a)
196196
@test isready(a)
197-
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
197+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(a)
198198
b = @spawn 1+2
199199
@test fetch(b) == 3
200200
end
@@ -207,8 +207,7 @@ end
207207
catch err
208208
err
209209
end
210-
ex = Dagger.Sch.unwrap_nested_exception(ex)
211-
ex_str = sprint(io->Base.showerror(io,ex))
210+
ex_str = sprint(io->Base.showerror(io, ex))
212211
@test occursin(r"^DTaskFailedException:", ex_str)
213212
@test occursin("Test", ex_str)
214213
@test !occursin("Root Task", ex_str)
@@ -218,44 +217,43 @@ end
218217
catch err
219218
err
220219
end
221-
ex = Dagger.Sch.unwrap_nested_exception(ex)
222-
ex_str = sprint(io->Base.showerror(io,ex))
220+
ex_str = sprint(io->Base.showerror(io, ex))
223221
@test occursin("Test", ex_str)
224222
@test occursin("Root Task", ex_str)
225223
end
226224
@testset "single dependent" begin
227225
a = @spawn error("Test")
228226
b = @spawn a+2
229-
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
227+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(a)
230228
end
231229
@testset "multi dependent" begin
232230
a = @spawn error("Test")
233231
b = @spawn a+2
234232
c = @spawn a*2
235-
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
236-
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
233+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(b)
234+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(c)
237235
end
238236
@testset "dependent chain" begin
239237
a = @spawn error("Test")
240-
@test_throws_unwrap Dagger.DTaskFailedException fetch(a)
238+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(a)
241239
b = @spawn a+1
242-
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
240+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(b)
243241
c = @spawn b+2
244-
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
242+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(c)
245243
end
246244
@testset "single input" begin
247245
a = @spawn 1+1
248246
b = @spawn (a->error("Test"))(a)
249247
@test fetch(a) == 2
250-
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
248+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(b)
251249
end
252250
@testset "multi input" begin
253251
a = @spawn 1+1
254252
b = @spawn 2*2
255253
c = @spawn ((a,b)->error("Test"))(a,b)
256254
@test fetch(a) == 2
257255
@test fetch(b) == 4
258-
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
256+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(c)
259257
end
260258
@testset "diamond" begin
261259
a = @spawn 1+1
@@ -265,7 +263,7 @@ end
265263
@test fetch(a) == 2
266264
@test fetch(b) == 3
267265
@test fetch(c) == 4
268-
@test_throws_unwrap Dagger.DTaskFailedException fetch(d)
266+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) fetch(d)
269267
end
270268
end
271269
@testset "remote spawn" begin
@@ -283,7 +281,7 @@ end
283281
t1 = Dagger.@spawn 1+"fail"
284282
Dagger.@spawn t1+1
285283
end
286-
@test_throws_unwrap Dagger.DTaskFailedException fetch(t2)
284+
@test_throws_unwrap (Dagger.DTaskFailedException, MethodError) fetch(t2)
287285
end
288286
@testset "undefined function" begin
289287
# Issues #254, #255

test/util.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ end
1414
replace_obj!(ex::Symbol, obj) = Expr(:(.), obj, QuoteNode(ex))
1515
replace_obj!(ex, obj) = ex
1616
function _test_throws_unwrap(terr, ex; to_match=[])
17-
@gensym rerr
17+
@gensym oerr rerr
1818
match_expr = Expr(:block)
1919
for m in to_match
2020
if m.head == :(=)
21-
lhs, rhs = replace_obj!(m.args[1], rerr), m.args[2]
21+
lhs, rhs = replace_obj!(m.args[1], oerr), m.args[2]
2222
push!(match_expr.args, :(@test $lhs == $rhs))
2323
elseif m.head == :call
2424
fn = m.args[1]
25-
lhs, rhs = replace_obj!(m.args[2], rerr), m.args[3]
25+
lhs, rhs = replace_obj!(m.args[2], oerr), m.args[3]
2626
if fn == :(<)
2727
push!(match_expr.args, :(@test startswith($lhs, $rhs)))
2828
elseif fn == :(>)
@@ -35,12 +35,17 @@ function _test_throws_unwrap(terr, ex; to_match=[])
3535
end
3636
end
3737
quote
38-
$rerr = try
39-
$(esc(ex))
38+
$oerr, $rerr = try
39+
nothing, $(esc(ex))
4040
catch err
41-
Dagger.Sch.unwrap_nested_exception(err)
41+
(err, Dagger.Sch.unwrap_nested_exception(err))
42+
end
43+
if $terr isa Tuple
44+
@test $oerr isa $terr[1]
45+
@test $rerr isa $terr[2]
46+
else
47+
@test $rerr isa $terr
4248
end
43-
@test $rerr isa $terr
4449
$match_expr
4550
end
4651
end

0 commit comments

Comments
 (0)