Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when queue cannot find task, expect queue runs next task #397

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Common/Background Queue/QueueRunRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class CioQueueRunRequest: QueueRunRequest {

// The task failed to execute like a HTTP failure. Update `lastFailedTask`.
updateWhileLoopLogicVariables(didTaskFail: true, taskJustExecuted: nextTaskToRunInventoryItem)
break
continue // quit loop early and move to next task.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this possibly fix the bug that the customer reported ?

}

logger.debug("queue tasks left to run: \(queueInventory.count)")
Expand Down
34 changes: 34 additions & 0 deletions Tests/Common/Background Queue/QueueRunRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,40 @@ class QueueRunRequestTest: UnitTest {

// MARK: runTasks

func test_runTasks_givenQueueTaskNotFoundInStorage_expectToContinueRunningQueue() {
// Setup the queue with 2 tasks.
// 1st task that cannot be found in queue storage.
// 2nd task that can be found and is expected to be executed.
let givenInventoryTaskStorageCannotFind = QueueTaskMetadata.random
let givenInventoryTaskInStorage = QueueTaskMetadata.random

var givenInventory = [givenInventoryTaskStorageCannotFind, givenInventoryTaskInStorage]
storageMock.getInventoryReturnValue = givenInventory

storageMock.getClosure = { taskStorageId in
if taskStorageId == givenInventoryTaskInStorage.taskPersistedId {
return QueueTask.random // queue storage found task in file system for 1 of the tasks
}

return nil
}

// setup runner and storage to run tasks successfully.
runnerMock.runTaskClosure = { _, onComplete in
onComplete(.success(()))
}
storageMock.deleteClosure = { taskStorageId in
givenInventory.removeAll(where: { $0.taskPersistedId == taskStorageId })
return true
}

runRequest.runTasks()

XCTAssertEqual(storageMock.getCallsCount, 2) // expect queue tried to get queue task from storage
XCTAssertEqual(runnerMock.runTaskCallsCount, 1)
XCTAssertEqual(requestManagerMock.requestCompleteCallsCount, 1)
}

// runTasks() performs async operations inside of it. A stackoverflow/infinite loop can occur if these async operations do not run in sequential order.
func test_runTasks_expectAsyncOperationsToPerformSequentially() {
// Events, in order, that are expected to happen
Expand Down