Skip to content

Commit 15fc3a1

Browse files
committed
Update resumable job tests
1 parent 75bca3f commit 15fc3a1

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

Tests/JobsPostgresTests/JobsTests.swift

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -686,33 +686,43 @@ final class JobsTests: XCTestCase {
686686

687687
func testResumableAndPausableJobs() async throws {
688688
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"
691693
}
692694
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)
694697

695698
let jobQueue = try await self.createJobQueue(numWorkers: 1, configuration: .init(), function: #function)
696699

697700
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
702712
}
703713
try await Task.sleep(for: .milliseconds(Int.random(in: 10..<50)))
704714
expectation.fulfill()
705715
}
706716

707717
let resumableJob = try await queue.push(
708-
TestParameters(value: 20),
718+
ResumableJob(),
709719
options: .init(
710720
priority: .lowest()
711721
)
712722
)
713723

714724
try await queue.push(
715-
TestParameters(value: 2025),
725+
TestParameters(),
716726
options: .init(
717727
priority: .normal()
718728
)
@@ -731,20 +741,19 @@ final class JobsTests: XCTestCase {
731741
}
732742

733743
let processingJobCount = try await jobQueue.queue.getJobs(withStatus: .processing)
734-
// Job 2 has been processed
735744
XCTAssertEqual(processingJobCount.count, 0)
736-
// Job 1 has not been processed
745+
737746
let pausedJobs = try await jobQueue.queue.getJobs(withStatus: .paused)
738747
XCTAssertEqual(pausedJobs.count, 1)
739-
// resume job 1
748+
740749
try await jobQueue.resumeJob(jobID: resumableJob)
741750

742751
await fulfillment(of: [expectation], timeout: 10)
743752
await serviceGroup.triggerGracefulShutdown()
744753
}
745754
}
746-
// verify job run order
747-
XCTAssertEqual(jobExecutionSequence.withLockedValue { $0 }, [2025, 20])
755+
XCTAssertEqual(didTestJobRun.withLockedValue { $0 }, true)
756+
XCTAssertEqual(didResumableJobRun.withLockedValue { $0 }, true)
748757
}
749758

750759
func testCancellableJob() async throws {

0 commit comments

Comments
 (0)