@@ -638,144 +638,3 @@ async fn test_bulk_spawn_empty_batch() -> anyhow::Result<()> {
638638
639639 Ok ( ( ) )
640640}
641-
642- #[ tokio:: test]
643- async fn test_cancel_pending_job ( ) -> anyhow:: Result < ( ) > {
644- let pool = helpers:: init_pool ( ) . await ?;
645- let config = JobSvcConfig :: builder ( )
646- . pool ( pool)
647- . build ( )
648- . expect ( "Failed to build JobsConfig" ) ;
649-
650- let mut jobs = Jobs :: init ( config) . await ?;
651- let spawner = jobs. add_initializer ( TestJobInitializer ) ;
652-
653- // Spawn a job scheduled far in the future so it stays pending
654- let job_id = JobId :: new ( ) ;
655- let schedule_at = chrono:: Utc :: now ( ) + chrono:: Duration :: hours ( 24 ) ;
656- spawner
657- . spawn_at ( job_id, TestJobConfig { delay_ms : 50 } , schedule_at)
658- . await ?;
659-
660- // Cancel the pending job
661- jobs. cancel_job ( job_id) . await ?;
662-
663- // Verify it's findable as a cancelled/completed entity
664- let found = jobs. find ( job_id) . await ?;
665- assert ! ( found. completed( ) , "Cancelled job should be completed" ) ;
666- assert ! ( found. cancelled( ) , "Job should be marked as cancelled" ) ;
667-
668- Ok ( ( ) )
669- }
670-
671- #[ tokio:: test]
672- async fn test_cancel_running_job_fails ( ) -> anyhow:: Result < ( ) > {
673- let pool = helpers:: init_pool ( ) . await ?;
674- let config = JobSvcConfig :: builder ( )
675- . pool ( pool)
676- . build ( )
677- . expect ( "Failed to build JobsConfig" ) ;
678-
679- let mut jobs = Jobs :: init ( config) . await ?;
680-
681- let started = Arc :: new ( Mutex :: new ( Vec :: < String > :: new ( ) ) ) ;
682- let completed = Arc :: new ( Mutex :: new ( Vec :: < String > :: new ( ) ) ) ;
683- let release = Arc :: new ( Notify :: new ( ) ) ;
684-
685- let spawner = jobs. add_initializer ( QueueJobInitializer {
686- job_type : JobType :: new ( "cancel-running-test" ) ,
687- started : Arc :: clone ( & started) ,
688- completed : Arc :: clone ( & completed) ,
689- release : Arc :: clone ( & release) ,
690- } ) ;
691-
692- jobs. start_poll ( )
693- . await
694- . expect ( "Failed to start job polling" ) ;
695-
696- let job_id = JobId :: new ( ) ;
697- spawner
698- . spawn ( job_id, QueueJobConfig { label : "X" . into ( ) } )
699- . await ?;
700-
701- // Wait for the job to start running
702- let mut attempts = 0 ;
703- loop {
704- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
705- if !started. lock ( ) . await . is_empty ( ) {
706- break ;
707- }
708- attempts += 1 ;
709- assert ! ( attempts < 100 , "Job never started" ) ;
710- }
711-
712- // Cancel on a running job should fail
713- let result = jobs. cancel_job ( job_id) . await ;
714- assert ! (
715- matches!( result, Err ( JobError :: CannotCancelJob ) ) ,
716- "Cancelling a running job should return JobNotPending, got err: {:?}" ,
717- result. err( ) ,
718- ) ;
719-
720- // Release the job so it completes normally
721- release. notify_one ( ) ;
722-
723- // Wait for completion
724- let mut attempts = 0 ;
725- loop {
726- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
727- let job = jobs. find ( job_id) . await ?;
728- if job. completed ( ) {
729- break ;
730- }
731- attempts += 1 ;
732- assert ! ( attempts < 100 , "Job never completed" ) ;
733- }
734-
735- Ok ( ( ) )
736- }
737-
738- #[ tokio:: test]
739- async fn test_cancel_already_completed_job_is_idempotent ( ) -> anyhow:: Result < ( ) > {
740- let pool = helpers:: init_pool ( ) . await ?;
741- let config = JobSvcConfig :: builder ( )
742- . pool ( pool)
743- . build ( )
744- . expect ( "Failed to build JobsConfig" ) ;
745-
746- let mut jobs = Jobs :: init ( config) . await ?;
747- let spawner = jobs. add_initializer ( TestJobInitializer ) ;
748-
749- jobs. start_poll ( )
750- . await
751- . expect ( "Failed to start job polling" ) ;
752-
753- let job_id = JobId :: new ( ) ;
754- spawner
755- . spawn ( job_id, TestJobConfig { delay_ms : 10 } )
756- . await ?;
757-
758- // Wait for the job to complete
759- let mut attempts = 0 ;
760- loop {
761- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
762- let job = jobs. find ( job_id) . await ?;
763- if job. completed ( ) {
764- break ;
765- }
766- attempts += 1 ;
767- assert ! ( attempts < 100 , "Job never completed" ) ;
768- }
769-
770- // Cancel on an already completed job is a no-op
771- jobs. cancel_job ( job_id) . await ?;
772-
773- let job = jobs. find ( job_id) . await ?;
774- assert ! (
775- !job. cancelled( ) ,
776- "Completed job should not be marked cancelled"
777- ) ;
778- assert ! ( job. completed( ) , "Job should still be completed" ) ;
779-
780- Ok ( ( ) )
781- }
0 commit comments