diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationState.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationState.ts index 417a9df2..b525c0df 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationState.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationState.ts @@ -24,7 +24,6 @@ export async function evaluateExpectationState( const tracker: ExpectationTracker = runner.tracker const timeSinceLastEvaluation = Date.now() - trackedExp.lastEvaluationTime - if (!trackedExp.session) trackedExp.session = {} if (trackedExp.session.hadError) return // There was an error during the session. if (trackedExp.session.expectationCanBeRemoved) return // The expectation has been removed diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/aborted.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/aborted.ts index bc50c532..db383140 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/aborted.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/aborted.ts @@ -14,7 +14,6 @@ export async function evaluateExpectationStateAborted({ }: EvaluateContext): Promise { assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.ABORTED) - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if (trackedExp.session.assignedWorker) { // Start by removing the expectation diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/fulfilled.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/fulfilled.ts index 2008f750..44ab3126 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/fulfilled.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/fulfilled.ts @@ -20,7 +20,6 @@ export async function evaluateExpectationStateFulfilled({ // TODO: Some monitor that is able to invalidate if it isn't fulfilled anymore? if (timeSinceLastEvaluation > tracker.getFulfilledWaitTime()) { - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if (trackedExp.session.assignedWorker) { try { diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/ready.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/ready.ts index cd0487a4..8f84fe70 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/ready.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/ready.ts @@ -17,7 +17,6 @@ export async function evaluateExpectationStateReady({ }: EvaluateContext): Promise { assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.READY) // Start working on it: - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if ( diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/removed.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/removed.ts index 843c611e..0b6d681e 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/removed.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/removed.ts @@ -17,7 +17,6 @@ export async function evaluateExpectationStateRemoved({ /** When true, the expectation can be removed */ let removeTheExpectation = false - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if (trackedExp.session.assignedWorker) { const removed = await trackedExp.session.assignedWorker.worker.removeExpectation(trackedExp.exp) diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/restarted.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/restarted.ts index 12eee9e3..3366047a 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/restarted.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/restarted.ts @@ -13,7 +13,6 @@ export async function evaluateExpectationStateRestarted({ }: EvaluateContext): Promise { assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.RESTARTED) - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if (trackedExp.session.assignedWorker) { // Start by removing the expectation diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/waiting.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/waiting.ts index ade07e31..20b0bda5 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/waiting.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluateExpectationStates/waiting.ts @@ -19,7 +19,6 @@ export async function evaluateExpectationStateWaiting({ assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.WAITING) // Check if the expectation is ready to start: - if (!trackedExp.session) trackedExp.session = {} await manager.workerAgents.assignWorkerToSession(trackedExp) if (trackedExp.session.assignedWorker) { diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts index 7d84d5d2..94cfec0c 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts @@ -278,7 +278,7 @@ export class EvaluationRunner { // Step 0: Reset the session: for (const trackedExp of tracked) { - trackedExp.session = null + trackedExp.session = {} } const postProcessSession = (trackedExp: TrackedExpectation) => { @@ -343,7 +343,7 @@ export class EvaluationRunner { // Step 1.5: Reset the session: // Because during the next iteration, the worker-assignment need to be done in series for (const trackedExp of tracked) { - trackedExp.session = null + trackedExp.session = {} } this.logger.debug(`Handle other states..`) diff --git a/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts b/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts index ce02c0eb..da0cb1a4 100644 --- a/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts +++ b/shared/packages/expectationManager/src/expectationTracker/lib/trackedExpectationAPI.ts @@ -170,7 +170,6 @@ export class TrackedExpectationAPI { * Handle an Expectation that had no worker assigned */ public noWorkerAssigned(trackedExp: TrackedExpectation): void { - if (!trackedExp.session) throw new Error('Internal error: noWorkerAssigned: session not set') if (trackedExp.session.assignedWorker) throw new Error('Internal error: noWorkerAssigned can only be called when assignedWorker is falsy') diff --git a/shared/packages/expectationManager/src/lib/trackedExpectation.ts b/shared/packages/expectationManager/src/lib/trackedExpectation.ts index 8ee2ce44..92b77a0c 100644 --- a/shared/packages/expectationManager/src/lib/trackedExpectation.ts +++ b/shared/packages/expectationManager/src/lib/trackedExpectation.ts @@ -54,8 +54,8 @@ export interface TrackedExpectation { targetCanBeUsedWhileTransferring?: boolean sourceIsPlaceholder?: boolean } - /** A storage which is persistant only for a short while, during an evaluation of the Expectation. */ - session: ExpectationStateHandlerSession | null + /** A storage which is persistent only for a short while, during an evaluation of the Expectation. */ + session: ExpectationStateHandlerSession } export function expLabel(exp: TrackedExpectation): string { @@ -120,6 +120,6 @@ export function getDefaultTrackedExpectation( }, prevStatusReasons: existingtrackedExp?.prevStatusReasons || {}, status: {}, - session: null, + session: {}, } }