@@ -651,151 +651,6 @@ async fn test_bulk_spawn_empty_batch() -> anyhow::Result<()> {
651651 Ok ( ( ) )
652652}
653653
654- #[ tokio:: test]
655- async fn test_cancel_pending_job ( ) -> anyhow:: Result < ( ) > {
656- let pool = helpers:: init_pool ( ) . await ?;
657- let config = JobSvcConfig :: builder ( )
658- . pool ( pool)
659- . build ( )
660- . expect ( "Failed to build JobsConfig" ) ;
661-
662- let mut jobs = Jobs :: init ( config) . await ?;
663- let spawner = jobs. add_initializer ( TestJobInitializer {
664- job_type : JobType :: new ( "cancel-pending-job" ) ,
665- } ) ;
666-
667- // Spawn a job scheduled far in the future so it stays pending
668- let job_id = JobId :: new ( ) ;
669- let schedule_at = chrono:: Utc :: now ( ) + chrono:: Duration :: hours ( 24 ) ;
670- spawner
671- . spawn_at ( job_id, TestJobConfig { delay_ms : 50 } , schedule_at)
672- . await ?;
673-
674- // Cancel the pending job
675- jobs. cancel_job ( job_id) . await ?;
676-
677- // Verify it's findable as a cancelled/completed entity
678- let found = jobs. find ( job_id) . await ?;
679- assert ! ( found. completed( ) , "Cancelled job should be completed" ) ;
680- assert ! ( found. cancelled( ) , "Job should be marked as cancelled" ) ;
681-
682- Ok ( ( ) )
683- }
684-
685- #[ tokio:: test]
686- async fn test_cancel_running_job_fails ( ) -> anyhow:: Result < ( ) > {
687- let pool = helpers:: init_pool ( ) . await ?;
688- let config = JobSvcConfig :: builder ( )
689- . pool ( pool)
690- . build ( )
691- . expect ( "Failed to build JobsConfig" ) ;
692-
693- let mut jobs = Jobs :: init ( config) . await ?;
694-
695- let started = Arc :: new ( Mutex :: new ( Vec :: < String > :: new ( ) ) ) ;
696- let completed = Arc :: new ( Mutex :: new ( Vec :: < String > :: new ( ) ) ) ;
697- let release = Arc :: new ( Notify :: new ( ) ) ;
698-
699- let spawner = jobs. add_initializer ( QueueJobInitializer {
700- job_type : JobType :: new ( "cancel-running-test" ) ,
701- started : Arc :: clone ( & started) ,
702- completed : Arc :: clone ( & completed) ,
703- release : Arc :: clone ( & release) ,
704- } ) ;
705-
706- jobs. start_poll ( )
707- . await
708- . expect ( "Failed to start job polling" ) ;
709-
710- let job_id = JobId :: new ( ) ;
711- spawner
712- . spawn ( job_id, QueueJobConfig { label : "X" . into ( ) } )
713- . await ?;
714-
715- // Wait for the job to start running
716- let mut attempts = 0 ;
717- loop {
718- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
719- if !started. lock ( ) . await . is_empty ( ) {
720- break ;
721- }
722- attempts += 1 ;
723- assert ! ( attempts < 100 , "Job never started" ) ;
724- }
725-
726- // Cancel on a running job should fail
727- let result = jobs. cancel_job ( job_id) . await ;
728- assert ! (
729- matches!( result, Err ( JobError :: CannotCancelJob ) ) ,
730- "Cancelling a running job should return JobNotPending, got err: {:?}" ,
731- result. err( ) ,
732- ) ;
733-
734- // Release the job so it completes normally
735- release. notify_one ( ) ;
736-
737- // Wait for completion
738- let mut attempts = 0 ;
739- loop {
740- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
741- let job = jobs. find ( job_id) . await ?;
742- if job. completed ( ) {
743- break ;
744- }
745- attempts += 1 ;
746- assert ! ( attempts < 100 , "Job never completed" ) ;
747- }
748-
749- Ok ( ( ) )
750- }
751-
752- #[ tokio:: test]
753- async fn test_cancel_already_completed_job_is_idempotent ( ) -> anyhow:: Result < ( ) > {
754- let pool = helpers:: init_pool ( ) . await ?;
755- let config = JobSvcConfig :: builder ( )
756- . pool ( pool)
757- . build ( )
758- . expect ( "Failed to build JobsConfig" ) ;
759-
760- let mut jobs = Jobs :: init ( config) . await ?;
761- let spawner = jobs. add_initializer ( TestJobInitializer {
762- job_type : JobType :: new ( "cancel-completed-job" ) ,
763- } ) ;
764-
765- jobs. start_poll ( )
766- . await
767- . expect ( "Failed to start job polling" ) ;
768-
769- let job_id = JobId :: new ( ) ;
770- spawner
771- . spawn ( job_id, TestJobConfig { delay_ms : 10 } )
772- . await ?;
773-
774- // Wait for the job to complete
775- let mut attempts = 0 ;
776- loop {
777- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
778- let job = jobs. find ( job_id) . await ?;
779- if job. completed ( ) {
780- break ;
781- }
782- attempts += 1 ;
783- assert ! ( attempts < 100 , "Job never completed" ) ;
784- }
785-
786- // Cancel on an already completed job is a no-op
787- jobs. cancel_job ( job_id) . await ?;
788-
789- let job = jobs. find ( job_id) . await ?;
790- assert ! (
791- !job. cancelled( ) ,
792- "Completed job should not be marked cancelled"
793- ) ;
794- assert ! ( job. completed( ) , "Job should still be completed" ) ;
795-
796- Ok ( ( ) )
797- }
798-
799654// -- await_completion tests --
800655
801656/// An initializer whose runner always returns an error.
@@ -891,40 +746,6 @@ async fn test_await_completion_on_error() -> anyhow::Result<()> {
891746 Ok ( ( ) )
892747}
893748
894- #[ tokio:: test]
895- async fn test_await_completion_on_cancel ( ) -> anyhow:: Result < ( ) > {
896- let pool = helpers:: init_pool ( ) . await ?;
897- let config = JobSvcConfig :: builder ( )
898- . pool ( pool)
899- . build ( )
900- . expect ( "Failed to build JobsConfig" ) ;
901-
902- let mut jobs = Jobs :: init ( config) . await ?;
903- let spawner = jobs. add_initializer ( TestJobInitializer {
904- job_type : JobType :: new ( "await-cancel-job" ) ,
905- } ) ;
906- jobs. start_poll ( ) . await ?;
907-
908- // Spawn a job scheduled far in the future so it stays pending
909- let job_id = JobId :: new ( ) ;
910- let schedule_at = chrono:: Utc :: now ( ) + chrono:: Duration :: hours ( 24 ) ;
911- spawner
912- . spawn_at ( job_id, TestJobConfig { delay_ms : 50 } , schedule_at)
913- . await ?;
914-
915- let jobs_clone = jobs. clone ( ) ;
916- let handle = tokio:: spawn ( async move { jobs_clone. await_completion ( job_id, None ) . await } ) ;
917-
918- // Give the waiter time to register before cancelling
919- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
920- jobs. cancel_job ( job_id) . await ?;
921-
922- let outcome = handle. await ??;
923- assert_eq ! ( outcome. state( ) , JobTerminalState :: Cancelled ) ;
924-
925- Ok ( ( ) )
926- }
927-
928749#[ tokio:: test]
929750async fn test_await_completion_already_completed ( ) -> anyhow:: Result < ( ) > {
930751 let pool = helpers:: init_pool ( ) . await ?;
0 commit comments