@@ -80,7 +80,7 @@ for idx in 1:5
80
80
@testset " Single Task Control Flow ($scope_str )" begin
81
81
@test ! test_finishes (" Single task running forever" ; max_evals= 1_000_000 , ignore_timeout= true ) do
82
82
local x
83
- Dagger. spawn_streaming () do
83
+ Dagger. spawn_streaming (;teardown = false ) do
84
84
x = Dagger. @spawn scope= rand (scopes) () -> begin
85
85
y = rand ()
86
86
sleep (1 )
@@ -92,15 +92,15 @@ for idx in 1:5
92
92
93
93
@test test_finishes (" Single task without result" ) do
94
94
local x
95
- Dagger. spawn_streaming () do
95
+ Dagger. spawn_streaming (;teardown = false ) do
96
96
x = Dagger. @spawn scope= rand (scopes) rand ()
97
97
end
98
98
@test fetch (x) === nothing
99
99
end
100
100
101
101
@test test_finishes (" Single task with result" ; max_evals= 1_000_000 ) do
102
102
local x
103
- Dagger. spawn_streaming () do
103
+ Dagger. spawn_streaming (;teardown = false ) do
104
104
x = Dagger. @spawn scope= rand (scopes) () -> begin
105
105
x = rand ()
106
106
if x < 0.1
@@ -116,7 +116,7 @@ for idx in 1:5
116
116
@testset " Non-Streaming Inputs ($scope_str )" begin
117
117
@test test_finishes (" () -> A" ) do
118
118
local A
119
- Dagger. spawn_streaming () do
119
+ Dagger. spawn_streaming (;teardown = false ) do
120
120
A = Dagger. @spawn scope= rand (scopes) accumulator ()
121
121
end
122
122
@test fetch (A) === nothing
@@ -127,7 +127,7 @@ for idx in 1:5
127
127
end
128
128
@test test_finishes (" 42 -> A" ) do
129
129
local A
130
- Dagger. spawn_streaming () do
130
+ Dagger. spawn_streaming (;teardown = false ) do
131
131
A = Dagger. @spawn scope= rand (scopes) accumulator (42 )
132
132
end
133
133
@test fetch (A) === nothing
@@ -138,7 +138,7 @@ for idx in 1:5
138
138
end
139
139
@test test_finishes (" (42, 43) -> A" ) do
140
140
local A
141
- Dagger. spawn_streaming () do
141
+ Dagger. spawn_streaming (;teardown = false ) do
142
142
A = Dagger. @spawn scope= rand (scopes) accumulator (42 , 43 )
143
143
end
144
144
@test fetch (A) === nothing
@@ -152,7 +152,7 @@ for idx in 1:5
152
152
@testset " Non-Streaming Outputs ($scope_str )" begin
153
153
@test test_finishes (" x -> A" ) do
154
154
local x, A
155
- Dagger. spawn_streaming () do
155
+ Dagger. spawn_streaming (;teardown = false ) do
156
156
x = Dagger. @spawn scope= rand (scopes) rand ()
157
157
end
158
158
Dagger. _without_options () do
@@ -168,7 +168,7 @@ for idx in 1:5
168
168
169
169
@test test_finishes (" x -> (A, B)" ) do
170
170
local x, A, B
171
- Dagger. spawn_streaming () do
171
+ Dagger. spawn_streaming (;teardown = false ) do
172
172
x = Dagger. @spawn scope= rand (scopes) rand ()
173
173
end
174
174
Dagger. _without_options () do
@@ -188,10 +188,45 @@ for idx in 1:5
188
188
end
189
189
end
190
190
191
+ @testset " Teardown" begin
192
+ @test test_finishes (" teardown=true" ; max_evals= 1_000_000 , ignore_timeout= true ) do
193
+ local x, y
194
+ Dagger. spawn_streaming (;teardown= true ) do
195
+ x = Dagger. @spawn scope= rand (scopes) () -> begin
196
+ sleep (0.1 )
197
+ return rand ()
198
+ end
199
+ y = Dagger. with_options (;stream_max_evals= 10 ) do
200
+ Dagger. @spawn scope= rand (scopes) identity (x)
201
+ end
202
+ end
203
+ @test fetch (y) === nothing
204
+ sleep (1 ) # Wait for teardown
205
+ @test istaskdone (x)
206
+ fetch (x)
207
+ end
208
+ @test ! test_finishes (" teardown=false" ; max_evals= 1_000_000 , ignore_timeout= true ) do
209
+ local x, y
210
+ Dagger. spawn_streaming (;teardown= false ) do
211
+ x = Dagger. @spawn scope= rand (scopes) () -> begin
212
+ sleep (0.1 )
213
+ return rand ()
214
+ end
215
+ y = Dagger. with_options (;stream_max_evals= 10 ) do
216
+ Dagger. @spawn scope= rand (scopes) identity (x)
217
+ end
218
+ end
219
+ @test fetch (y) === nothing
220
+ sleep (1 ) # Wait to ensure `x` task is still running
221
+ @test ! istaskdone (x)
222
+ @test_throws_unwrap InterruptException fetch (x)
223
+ end
224
+ end
225
+
191
226
@testset " Multiple Tasks ($scope_str )" begin
192
227
@test test_finishes (" x -> A" ) do
193
228
local x, A
194
- Dagger. spawn_streaming () do
229
+ Dagger. spawn_streaming (;teardown = false ) do
195
230
x = Dagger. @spawn scope= rand (scopes) rand ()
196
231
A = Dagger. @spawn scope= rand (scopes) accumulator (x)
197
232
end
@@ -205,7 +240,7 @@ for idx in 1:5
205
240
206
241
@test test_finishes (" (x, A)" ) do
207
242
local x, A
208
- Dagger. spawn_streaming () do
243
+ Dagger. spawn_streaming (;teardown = false ) do
209
244
x = Dagger. @spawn scope= rand (scopes) rand ()
210
245
A = Dagger. @spawn scope= rand (scopes) accumulator (1.0 )
211
246
end
@@ -219,7 +254,7 @@ for idx in 1:5
219
254
220
255
@test test_finishes (" x -> y -> A" ) do
221
256
local x, y, A
222
- Dagger. spawn_streaming () do
257
+ Dagger. spawn_streaming (;teardown = false ) do
223
258
x = Dagger. @spawn scope= rand (scopes) rand ()
224
259
y = Dagger. @spawn scope= rand (scopes) x+ 1
225
260
A = Dagger. @spawn scope= rand (scopes) accumulator (y)
@@ -235,7 +270,7 @@ for idx in 1:5
235
270
236
271
@test test_finishes (" x -> (y, A)" ) do
237
272
local x, y, A
238
- Dagger. spawn_streaming () do
273
+ Dagger. spawn_streaming (;teardown = false ) do
239
274
x = Dagger. @spawn scope= rand (scopes) rand ()
240
275
y = Dagger. @spawn scope= rand (scopes) x+ 1
241
276
A = Dagger. @spawn scope= rand (scopes) accumulator (x)
@@ -251,7 +286,7 @@ for idx in 1:5
251
286
252
287
@test test_finishes (" (x, y) -> A" ) do
253
288
local x, y, A
254
- Dagger. spawn_streaming () do
289
+ Dagger. spawn_streaming (;teardown = false ) do
255
290
x = Dagger. @spawn scope= rand (scopes) rand ()
256
291
y = Dagger. @spawn scope= rand (scopes) rand ()
257
292
A = Dagger. @spawn scope= rand (scopes) accumulator (x, y)
@@ -267,7 +302,7 @@ for idx in 1:5
267
302
268
303
@test test_finishes (" (x, y) -> z -> A" ) do
269
304
local x, y, z, A
270
- Dagger. spawn_streaming () do
305
+ Dagger. spawn_streaming (;teardown = false ) do
271
306
x = Dagger. @spawn scope= rand (scopes) rand ()
272
307
y = Dagger. @spawn scope= rand (scopes) rand ()
273
308
z = Dagger. @spawn scope= rand (scopes) x + y
@@ -285,7 +320,7 @@ for idx in 1:5
285
320
286
321
@test test_finishes (" x -> (y, z) -> A" ) do
287
322
local x, y, z, A
288
- Dagger. spawn_streaming () do
323
+ Dagger. spawn_streaming (;teardown = false ) do
289
324
x = Dagger. @spawn scope= rand (scopes) rand ()
290
325
y = Dagger. @spawn scope= rand (scopes) x + 1
291
326
z = Dagger. @spawn scope= rand (scopes) x + 2
@@ -303,7 +338,7 @@ for idx in 1:5
303
338
304
339
@test test_finishes (" (x, y) -> z -> (A, B)" ) do
305
340
local x, y, z, A, B
306
- Dagger. spawn_streaming () do
341
+ Dagger. spawn_streaming (;teardown = false ) do
307
342
x = Dagger. @spawn scope= rand (scopes) rand ()
308
343
y = Dagger. @spawn scope= rand (scopes) rand ()
309
344
z = Dagger. @spawn scope= rand (scopes) x + y
@@ -328,7 +363,7 @@ for idx in 1:5
328
363
for T in (Float64, Int32, BigFloat)
329
364
@test test_finishes (" Stream eltype $T " ) do
330
365
local x, A
331
- Dagger. spawn_streaming () do
366
+ Dagger. spawn_streaming (;teardown = false ) do
332
367
x = Dagger. @spawn scope= rand (scopes) rand (T)
333
368
A = Dagger. @spawn scope= rand (scopes) accumulator (x)
334
369
end
@@ -344,13 +379,13 @@ for idx in 1:5
344
379
345
380
@testset " Max Evals ($scope_str )" begin
346
381
@test test_finishes (" max_evals=0" ; max_evals= 0 ) do
347
- @test_throws ArgumentError Dagger. spawn_streaming () do
382
+ @test_throws ArgumentError Dagger. spawn_streaming (;teardown = false ) do
348
383
A = Dagger. @spawn scope= rand (scopes) accumulator ()
349
384
end
350
385
end
351
386
@test test_finishes (" max_evals=1" ; max_evals= 1 ) do
352
387
local A
353
- Dagger. spawn_streaming () do
388
+ Dagger. spawn_streaming (;teardown = false ) do
354
389
A = Dagger. @spawn scope= rand (scopes) accumulator ()
355
390
end
356
391
@test fetch (A) === nothing
@@ -360,7 +395,7 @@ for idx in 1:5
360
395
end
361
396
@test test_finishes (" max_evals=100" ; max_evals= 100 ) do
362
397
local A
363
- Dagger. spawn_streaming () do
398
+ Dagger. spawn_streaming (;teardown = false ) do
364
399
A = Dagger. @spawn scope= rand (scopes) accumulator ()
365
400
end
366
401
@test fetch (A) === nothing
0 commit comments