Skip to content

Commit

Permalink
chore: refactor: session property
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Sep 5, 2024
1 parent cf207e6 commit fb1e55d
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function evaluateExpectationStateAborted({
}: EvaluateContext): Promise<void> {
assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.ABORTED)

if (!trackedExp.session) trackedExp.session = {}
await manager.workerAgents.assignWorkerToSession(trackedExp)
if (trackedExp.session.assignedWorker) {
// Start by removing the expectation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function evaluateExpectationStateReady({
}: EvaluateContext): Promise<void> {
assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.READY)
// Start working on it:
if (!trackedExp.session) trackedExp.session = {}
await manager.workerAgents.assignWorkerToSession(trackedExp)

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function evaluateExpectationStateRestarted({
}: EvaluateContext): Promise<void> {
assertState(trackedExp, ExpectedPackageStatusAPI.WorkStatusState.RESTARTED)

if (!trackedExp.session) trackedExp.session = {}
await manager.workerAgents.assignWorkerToSession(trackedExp)
if (trackedExp.session.assignedWorker) {
// Start by removing the expectation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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..`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -120,6 +120,6 @@ export function getDefaultTrackedExpectation(
},
prevStatusReasons: existingtrackedExp?.prevStatusReasons || {},
status: {},
session: null,
session: {},
}
}

0 comments on commit fb1e55d

Please sign in to comment.