Skip to content

Commit 73a24ad

Browse files
committed
tests: Test DTaskFailedException inner type
1 parent 1d796a2 commit 73a24ad

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

test/mutation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
x = Dagger.@mutable worker=w Ref{Int}()
4949
@test fetch(Dagger.@spawn mutable_update!(x)) == w
5050
wo_scope = Dagger.ProcessScope(wo)
51-
@test_throws_unwrap Dagger.DTaskFailedException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
51+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
5252
end
5353
end # @testset "@mutable"
5454

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) 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) 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/scheduler.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ end
182182
@testset "allow errors" begin
183183
opts = ThunkOptions(;allow_errors=true)
184184
a = delayed(error; options=opts)("Test")
185-
@test_throws_unwrap Dagger.DTaskFailedException collect(a)
185+
@test_throws_unwrap (Dagger.DTaskFailedException, ErrorException) collect(a)
186186
end
187187
end
188188

@@ -396,7 +396,7 @@ end
396396
([Dagger.tochunk(MyStruct(1)), Dagger.tochunk(1)], sizeof(MyStruct)+sizeof(Int)),
397397
]
398398
for arg in args
399-
if arg isa Chunk
399+
if arg isa Dagger.Chunk
400400
aff = Dagger.affinity(arg)
401401
@test aff[1] == OSProc(1)
402402
@test aff[2] == MemPool.approx_size(MemPool.poolget(arg.handle))
@@ -477,7 +477,7 @@ end
477477
@test res == 2
478478
@testset "self as input" begin
479479
a = delayed(dynamic_add_thunk_self_dominated)(1)
480-
@test_throws_unwrap Dagger.Sch.DynamicThunkException reason="Cannot fetch result of dominated thunk" collect(Context(), a)
480+
@test_throws_unwrap (RemoteException, Dagger.Sch.DynamicThunkException) reason="Cannot fetch result of dominated thunk" collect(Context(), a)
481481
end
482482
end
483483
@testset "Fetch/Wait" begin
@@ -487,11 +487,11 @@ end
487487
end
488488
@testset "self" begin
489489
a = delayed(dynamic_fetch_self)(1)
490-
@test_throws_unwrap Dagger.Sch.DynamicThunkException reason="Cannot fetch own result" collect(Context(), a)
490+
@test_throws_unwrap (RemoteException, Dagger.Sch.DynamicThunkException) reason="Cannot fetch own result" collect(Context(), a)
491491
end
492492
@testset "dominated" begin
493493
a = delayed(identity)(delayed(dynamic_fetch_dominated)(1))
494-
@test_throws_unwrap Dagger.Sch.DynamicThunkException reason="Cannot fetch result of dominated thunk" collect(Context(), a)
494+
@test_throws_unwrap (RemoteException, Dagger.Sch.DynamicThunkException) reason="Cannot fetch result of dominated thunk" collect(Context(), a)
495495
end
496496
end
497497
end
@@ -540,7 +540,7 @@ end
540540
t = Dagger.@spawn scope=Dagger.scope(worker=1, thread=1) sleep(100)
541541
start_time = time_ns()
542542
Dagger.cancel!(t)
543-
@test_throws_unwrap Dagger.DTaskFailedException fetch(t)
543+
@test_throws_unwrap (Dagger.DTaskFailedException, InterruptException) fetch(t)
544544
t = Dagger.@spawn scope=Dagger.scope(worker=1, thread=1) yield()
545545
fetch(t)
546546
finish_time = time_ns()

test/scopes.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#@everywhere ENV["JULIA_DEBUG"] = "Dagger"
12
@testset "Chunk Scopes" begin
23
wid1, wid2 = addprocs(2, exeflags=["-t 2"])
34
@everywhere [wid1,wid2] using Dagger
@@ -56,7 +57,7 @@
5657

5758
# Different nodes
5859
for (ch1, ch2) in [(ns1_ch, ns2_ch), (ns2_ch, ns1_ch)]
59-
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
60+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
6061
end
6162
end
6263
@testset "Process Scope" begin
@@ -75,15 +76,15 @@
7576

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

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

8485
# Different process and node
8586
for (ch1, ch2) in [(ps1_ch, ns2_ch), (ns2_ch, ps1_ch)]
86-
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
87+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
8788
end
8889
end
8990
@testset "Exact Scope" begin
@@ -104,14 +105,14 @@
104105

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

110111
# Same process, different processor
111112
es1_2 = ExactScope(Dagger.ThreadProc(wid1, 2))
112113
es1_2_ch = Dagger.tochunk(nothing, OSProc(), es1_2)
113114
for (ch1, ch2) in [(es1_ch, es1_2_ch), (es1_2_ch, es1_ch)]
114-
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
115+
@test_throws_unwrap (Dagger.DTaskFailedException, Dagger.Sch.SchedulingException) reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
115116
end
116117
end
117118
@testset "Union Scope" begin

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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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 == :(=)
@@ -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)