Skip to content

Commit 999bdd7

Browse files
committed
Fix @test_throws_unwrap tests
`unwrap_nested_exception()` now supports `DTaskFailedException` so we can match against the real exceptions thrown.
1 parent 079e9fa commit 999bdd7

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

test/mutation.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Dagger.Sch: SchedulingException
2+
13
@everywhere begin
24
struct DynamicHistogram
35
bins::Vector{Float64}
@@ -48,7 +50,7 @@ end
4850
x = Dagger.@mutable worker=w Ref{Int}()
4951
@test fetch(Dagger.@spawn mutable_update!(x)) == w
5052
wo_scope = Dagger.ProcessScope(wo)
51-
@test_throws_unwrap Dagger.DTaskFailedException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
53+
@test_throws_unwrap SchedulingException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
5254
end
5355
end # @testset "@mutable"
5456

test/processors.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Distributed
22
import Dagger: Context, Processor, OSProc, ThreadProc, get_parent, get_processors
3-
import Dagger.Sch: ThunkOptions
3+
import Dagger.Sch: ThunkOptions, SchedulingException
44

55
@everywhere begin
66

@@ -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 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 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: 3 additions & 3 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 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))
@@ -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 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Dagger.Sch: SchedulingException
2+
13
@testset "Chunk Scopes" begin
24
wid1, wid2 = addprocs(2, exeflags=["-t 2"])
35
@everywhere [wid1,wid2] using Dagger
@@ -56,7 +58,7 @@
5658

5759
# Different nodes
5860
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)
61+
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
6062
end
6163
end
6264
@testset "Process Scope" begin
@@ -75,15 +77,15 @@
7577

7678
# Different process
7779
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)
80+
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
7981
end
8082

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

8486
# Different process and node
8587
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)
88+
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
8789
end
8890
end
8991
@testset "Exact Scope" begin
@@ -104,14 +106,14 @@
104106

105107
# Different process, different processor
106108
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)
109+
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
108110
end
109111

110112
# Same process, different processor
111113
es1_2 = ExactScope(Dagger.ThreadProc(wid1, 2))
112114
es1_2_ch = Dagger.tochunk(nothing, OSProc(), es1_2)
113115
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)
116+
@test_throws_unwrap SchedulingException reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
115117
end
116118
end
117119
@testset "Union Scope" begin

test/thunk.jl

Lines changed: 13 additions & 14 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 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 ErrorException fetch(a)
198198
b = @spawn 1+2
199199
@test fetch(b) == 3
200200
end
@@ -207,7 +207,6 @@ end
207207
catch err
208208
err
209209
end
210-
ex = Dagger.Sch.unwrap_nested_exception(ex)
211210
ex_str = sprint(io->Base.showerror(io,ex))
212211
@test occursin(r"^DTaskFailedException:", ex_str)
213212
@test occursin("Test", ex_str)
@@ -218,44 +217,43 @@ end
218217
catch err
219218
err
220219
end
221-
ex = Dagger.Sch.unwrap_nested_exception(ex)
222220
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 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 ErrorException fetch(b)
234+
@test_throws_unwrap 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 ErrorException fetch(a)
241239
b = @spawn a+1
242-
@test_throws_unwrap Dagger.DTaskFailedException fetch(b)
240+
@test_throws_unwrap ErrorException fetch(b)
243241
c = @spawn b+2
244-
@test_throws_unwrap Dagger.DTaskFailedException fetch(c)
242+
@test_throws_unwrap 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 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 ErrorException fetch(c)
259257
end
260258
@testset "diamond" begin
261259
a = @spawn 1+1
@@ -265,9 +263,10 @@ 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 ErrorException fetch(d)
269267
end
270268
end
269+
271270
@testset "remote spawn" begin
272271
a = fetch(Distributed.@spawnat 2 Dagger.@spawn 1+2)
273272
@test Dagger.Sch.EAGER_INIT[]
@@ -283,7 +282,7 @@ end
283282
t1 = Dagger.@spawn 1+"fail"
284283
Dagger.@spawn t1+1
285284
end
286-
@test_throws_unwrap Dagger.DTaskFailedException fetch(t2)
285+
@test_throws_unwrap MethodError fetch(t2)
287286
end
288287
@testset "undefined function" begin
289288
# Issues #254, #255

0 commit comments

Comments
 (0)