From c8266d63939d21d57cde6f08f6e37e6435543c3e Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Tue, 26 Mar 2024 16:05:16 +0100 Subject: [PATCH] fix: ensure noWorkerAssignedTime is reset when there is an assigned worker This is to avoid a possible case of where Fulfilled expectations where left with noWorkerAssignedTime being set.. --- .../expectationTracker/lib/trackedExpectationAPI.ts | 10 +++++++++- .../src/internalManager/lib/trackedWorkerAgents.ts | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts b/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts index 66eaf92c..5995b4ff 100644 --- a/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts +++ b/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts @@ -187,7 +187,15 @@ export class TrackedExpectationAPI { noAssignedWorkerReason = trackedExp.session.noAssignedWorkerReason } - if (!trackedExp.noWorkerAssignedTime) trackedExp.noWorkerAssignedTime = Date.now() + if (!trackedExp.noWorkerAssignedTime) { + const now = Date.now() + this.logger.error( + `Setting trackedExp.noWorkerAssignedTime of "${expLabel(trackedExp)}" to ${now} (reason: ${ + noAssignedWorkerReason.tech + })` + ) + trackedExp.noWorkerAssignedTime = now + } // Special case: When WAITING and no worker was assigned, return to NEW so that another worker might be assigned: if (trackedExp.state === ExpectedPackageStatusAPI.WorkStatusState.WAITING) { diff --git a/shared/packages/expectationManager/src/internalManager/lib/trackedWorkerAgents.ts b/shared/packages/expectationManager/src/internalManager/lib/trackedWorkerAgents.ts index 88ee2513..6ab38f0e 100644 --- a/shared/packages/expectationManager/src/internalManager/lib/trackedWorkerAgents.ts +++ b/shared/packages/expectationManager/src/internalManager/lib/trackedWorkerAgents.ts @@ -174,7 +174,11 @@ export class TrackedWorkerAgents { public async assignWorkerToSession(trackedExp: TrackedExpectation): Promise { const session: ExpectationStateHandlerSession | null = trackedExp.session if (!session) throw new Error('ExpectationManager: Internal error: Session not set') - if (session.assignedWorker) return // A worker has already been assigned + if (session.assignedWorker) { + // A worker has already been assigned + trackedExp.noWorkerAssignedTime = null + return + } if (!trackedExp.availableWorkers.size) { session.noAssignedWorkerReason = { user: `No workers available`, tech: `No workers available` }