@@ -686,33 +686,43 @@ final class JobsTests: XCTestCase {
686
686
687
687
func testResumableAndPausableJobs( ) async throws {
688
688
struct TestParameters : JobParameters {
689
- static let jobName = " testResumableAndPausableJobs "
690
- let value : Int
689
+ static let jobName = " TestJob "
690
+ }
691
+ struct ResumableJob : JobParameters {
692
+ static let jobName = " ResumanableJob "
691
693
}
692
694
let expectation = XCTestExpectation ( description: " TestJob.execute was called " , expectedFulfillmentCount: 2 )
693
- let jobExecutionSequence : NIOLockedValueBox < [ Int ] > = . init( [ ] )
695
+ let didResumableJobRun : NIOLockedValueBox < Bool > = . init( false )
696
+ let didTestJobRun : NIOLockedValueBox < Bool > = . init( false )
694
697
695
698
let jobQueue = try await self . createJobQueue ( numWorkers: 1 , configuration: . init( ) , function: #function)
696
699
697
700
try await testPriorityJobQueue ( jobQueue: jobQueue) { queue in
698
- queue. registerJob ( parameters: TestParameters . self) { parameters, context in
699
- context. logger. info ( " Parameters= \( parameters. value) " )
700
- jobExecutionSequence. withLockedValue {
701
- $0. append ( parameters. value)
701
+ queue. registerJob ( parameters: TestParameters . self) { parameters, _ in
702
+ didTestJobRun. withLockedValue {
703
+ $0 = true
704
+ }
705
+ try await Task . sleep ( for: . milliseconds( Int . random ( in: 10 ..< 50 ) ) )
706
+ expectation. fulfill ( )
707
+ }
708
+
709
+ queue. registerJob ( parameters: ResumableJob . self) { parameters, _ in
710
+ didResumableJobRun. withLockedValue {
711
+ $0 = true
702
712
}
703
713
try await Task . sleep ( for: . milliseconds( Int . random ( in: 10 ..< 50 ) ) )
704
714
expectation. fulfill ( )
705
715
}
706
716
707
717
let resumableJob = try await queue. push (
708
- TestParameters ( value : 20 ) ,
718
+ ResumableJob ( ) ,
709
719
options: . init(
710
720
priority: . lowest( )
711
721
)
712
722
)
713
723
714
724
try await queue. push (
715
- TestParameters ( value : 2025 ) ,
725
+ TestParameters ( ) ,
716
726
options: . init(
717
727
priority: . normal( )
718
728
)
@@ -731,20 +741,19 @@ final class JobsTests: XCTestCase {
731
741
}
732
742
733
743
let processingJobCount = try await jobQueue. queue. getJobs ( withStatus: . processing)
734
- // Job 2 has been processed
735
744
XCTAssertEqual ( processingJobCount. count, 0 )
736
- // Job 1 has not been processed
745
+
737
746
let pausedJobs = try await jobQueue. queue. getJobs ( withStatus: . paused)
738
747
XCTAssertEqual ( pausedJobs. count, 1 )
739
- // resume job 1
748
+
740
749
try await jobQueue. resumeJob ( jobID: resumableJob)
741
750
742
751
await fulfillment ( of: [ expectation] , timeout: 10 )
743
752
await serviceGroup. triggerGracefulShutdown ( )
744
753
}
745
754
}
746
- // verify job run order
747
- XCTAssertEqual ( jobExecutionSequence . withLockedValue { $0 } , [ 2025 , 20 ] )
755
+ XCTAssertEqual ( didTestJobRun . withLockedValue { $0 } , true )
756
+ XCTAssertEqual ( didResumableJobRun . withLockedValue { $0 } , true )
748
757
}
749
758
750
759
func testCancellableJob( ) async throws {
0 commit comments