@@ -400,13 +400,18 @@ end
400
400
end
401
401
402
402
state = Dagger. Sch. EAGER_STATE[]
403
- tproc1 = Dagger. ThreadProc (1 , 1 )
404
- tproc2 = Dagger. ThreadProc (first (workers ()), 1 )
405
- procs = [tproc1, tproc2 ]
403
+ tproc1_1 = Dagger. ThreadProc (1 , 1 )
404
+ tproc2_1 = Dagger. ThreadProc (first (workers ()), 1 )
405
+ procs = [tproc1_1, tproc2_1 ]
406
406
407
- pres1 = state. worker_time_pressure[1 ][tproc1]
408
- pres2 = state. worker_time_pressure[first (workers ())][tproc2]
407
+ # Ensure that this worker has been used at least once
408
+ fetch (Dagger. @spawn scope= Dagger. ExactScope (tproc2_1) 1 + 1 )
409
+
410
+ # pres1_1 = state.worker_time_pressure[1][tproc1_1]
411
+ # pres2_1 = state.worker_time_pressure[first(workers())][tproc2_1]
409
412
tx_rate = state. transfer_rate[]
413
+ tx_xfer_cost = 1e6
414
+ sig_unknown_cost = 1e9
410
415
411
416
for (args, tx_size) in [
412
417
([1 , 2 ], 0 ),
@@ -433,18 +438,18 @@ end
433
438
Dagger. Sch. collect_task_inputs! (state, t)
434
439
sorted_procs, costs = Dagger. Sch. estimate_task_costs (state, procs, t)
435
440
436
- @test tproc1 in sorted_procs
437
- @test tproc2 in sorted_procs
441
+ @test tproc1_1 in sorted_procs
442
+ @test tproc2_1 in sorted_procs
438
443
if length (cargs) > 0
439
- @test sorted_procs[1 ] == tproc1
440
- @test sorted_procs[2 ] == tproc2
444
+ @test sorted_procs[1 ] == tproc1_1
445
+ @test sorted_procs[2 ] == tproc2_1
441
446
end
442
447
443
- @test haskey (costs, tproc1 )
444
- @test haskey (costs, tproc2 )
445
- @test costs[tproc1 ] ≈ pres1 # All chunks are local
448
+ @test haskey (costs, tproc1_1 )
449
+ @test haskey (costs, tproc2_1 )
450
+ @test costs[tproc1_1 ] ≈ #= pres1_1 + =# sig_unknown_cost # All chunks are local, and this signature is unknown
446
451
if nprocs () > 1
447
- @test costs[tproc2 ] ≈ (tx_size/ tx_rate) + pres2 # All chunks are remote
452
+ @test costs[tproc2_1 ] ≈ (tx_size/ tx_rate) + tx_xfer_cost + #= pres2_1 + =# sig_unknown_cost # All chunks are remote, and this signature is unknown
448
453
end
449
454
end
450
455
end
@@ -564,12 +569,32 @@ end
564
569
end
565
570
566
571
@testset " Cancellation" begin
572
+ # Ready task cancellation
573
+ start_time = time_ns ()
567
574
t = Dagger. @spawn scope= Dagger. scope (worker= 1 , thread= 1 ) sleep (100 )
575
+ Dagger. cancel! (t)
576
+ @test timedwait (()-> istaskdone (t), 10 ) == :ok
577
+ if istaskdone (t)
578
+ @test_throws_unwrap (Dagger. DTaskFailedException, InterruptException) fetch (t)
579
+ @test (time_ns () - start_time) * 1e-9 < 100
580
+ end
581
+
582
+ # Running task cancellation
568
583
start_time = time_ns ()
584
+ t = Dagger. @spawn scope= Dagger. scope (worker= 1 , thread= 1 ) sleep (100 )
585
+ sleep (0.1 ) # Give the scheduler a chance to schedule the task
569
586
Dagger. cancel! (t)
570
- @test_throws_unwrap (Dagger. DTaskFailedException, InterruptException) fetch (t)
587
+ @test timedwait (()-> istaskdone (t), 10 ) == :ok
588
+ if istaskdone (t)
589
+ @test_throws_unwrap (Dagger. DTaskFailedException, InterruptException) fetch (t)
590
+ @test (time_ns () - start_time) * 1e-9 < 100
591
+ end
592
+
593
+ # Normal task execution
594
+ start_time = time_ns ()
571
595
t = Dagger. @spawn scope= Dagger. scope (worker= 1 , thread= 1 ) yield ()
572
- fetch (t)
573
- finish_time = time_ns ()
574
- @test (finish_time - start_time) * 1e-9 < 100
596
+ @test timedwait (()-> istaskdone (t), 10 ) == :ok
597
+ if istaskdone (t)
598
+ @test (time_ns () - start_time) * 1e-9 < 100
599
+ end
575
600
end
0 commit comments