@@ -852,21 +852,15 @@ final class JobsTests: XCTestCase {
852
852
XCTAssertEqual ( didRunNoneCancelledJob. withLockedValue { $0 } , true )
853
853
}
854
854
855
- func testJobRetention ( ) async throws {
855
+ func testCompletedJobRetention ( ) async throws {
856
856
struct TestParameters : JobParameters {
857
- static let jobName = " testJobRetention "
857
+ static let jobName = " testCompletedJobRetention "
858
858
let value : Int
859
859
}
860
860
let expectation = XCTestExpectation ( description: " TestJob.execute was called " , expectedFulfillmentCount: 3 )
861
861
try await self . testJobQueue (
862
862
numWorkers: 1 ,
863
- configuration: . init(
864
- retentionPolicy: . init(
865
- cancelled: . retain,
866
- completed: . retain,
867
- failed: . retain
868
- )
869
- )
863
+ configuration: . init( retentionPolicy: . init( completed: . retain) )
870
864
) { jobQueue in
871
865
jobQueue. registerJob ( parameters: TestParameters . self) { parameters, context in
872
866
context. logger. info ( " Parameters= \( parameters. value) " )
@@ -887,26 +881,47 @@ final class JobsTests: XCTestCase {
887
881
}
888
882
}
889
883
884
+ func testCancelledJobRetention( ) async throws {
885
+ let jobQueue = try await self . createJobQueue (
886
+ numWorkers: 1 ,
887
+ configuration: . init( retentionPolicy: . init( cancelled: . retain) )
888
+ )
889
+ let jobName = JobName < Int > ( " testCancelledJobRetention " )
890
+ jobQueue. registerJob ( name: jobName) { _, _ in }
891
+
892
+ try await withThrowingTaskGroup ( of: Void . self) { group in
893
+ group. addTask {
894
+ // run postgres client
895
+ await jobQueue. queue. client. run ( )
896
+ }
897
+ try await jobQueue. queue. migrations. apply ( client: jobQueue. queue. client, logger: jobQueue. logger, dryRun: false )
898
+
899
+ let jobId = try await jobQueue. push ( jobName, parameters: 1 )
900
+ let jobId2 = try await jobQueue. push ( jobName, parameters: 2 )
901
+
902
+ try await jobQueue. cancelJob ( jobID: jobId)
903
+ try await jobQueue. cancelJob ( jobID: jobId2)
904
+
905
+ var cancelledJobs = try await jobQueue. queue. getJobs ( withStatus: . cancelled)
906
+ XCTAssertEqual ( cancelledJobs. count, 2 )
907
+ try await jobQueue. queue. cleanup ( cancelledJobs: . remove( maxAge: . seconds( 0 ) ) )
908
+ cancelledJobs = try await jobQueue. queue. getJobs ( withStatus: . cancelled)
909
+ XCTAssertEqual ( cancelledJobs. count, 0 )
910
+
911
+ group. cancelAll ( )
912
+ }
913
+ }
914
+
890
915
func testCleanupJob( ) async throws {
891
916
try await self . testJobQueue (
892
917
numWorkers: 1 ,
893
- configuration: . init(
894
- retentionPolicy: . init(
895
- cancelled: . retain,
896
- completed: . doNotRetain,
897
- failed: . retain
898
- )
899
- )
918
+ configuration: . init( retentionPolicy: . init( failed: . retain) )
900
919
) { jobQueue in
901
920
try await self . testJobQueue (
902
921
numWorkers: 1 ,
903
922
configuration: . init(
904
923
queueName: " SecondQueue " ,
905
- retentionPolicy: . init(
906
- cancelled: . retain,
907
- completed: . doNotRetain,
908
- failed: . retain
909
- )
924
+ retentionPolicy: . init( failed: . retain)
910
925
)
911
926
) { jobQueue2 in
912
927
let ( stream, cont) = AsyncStream . makeStream ( of: Void . self)
0 commit comments