Skip to content

Commit

Permalink
fix: add .skipEvaluationCount property
Browse files Browse the repository at this point in the history
This is to even out the evaluations of expectations in the case where we skip evaluating states.
  • Loading branch information
nytamin committed Feb 18, 2025
1 parent e215d1f commit 1b0246b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export async function evaluateExpectationState(
const manager: InternalManager = runner.manager
const tracker: ExpectationTracker = runner.tracker

trackedExp.skipEvaluationCount = 0 // Reset the skip count

const timeSinceLastEvaluation = Date.now() - trackedExp.lastEvaluationTime
if (trackedExp.session.hadError) return // There was an error during the session.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ export class EvaluationRunner {
if (trackedWithState.length) {
// We're using a PromisePool so that we don't send out an unlimited number of parallel requests to the workers.

for (const trackedExp of trackedWithState) {
trackedExp.skipEvaluationCount++
}

const startTime = Date.now()
/** How long to wait before skipping ahead to process the next state */
const allowSkipTime =
Expand Down
10 changes: 10 additions & 0 deletions shared/packages/expectationManager/src/lib/trackedExpectation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export interface TrackedExpectation {
noAvailableWorkersReason: Reason
/** Timestamp of the last time the expectation was evaluated. */
lastEvaluationTime: number
/**
* Number of times the expectation has been skipped (this is reset once the expectation is evaluated)
* This is used to ensure that expectations are evaluated evenly
*/
skipEvaluationCount: number
/** Timestamp to track how long the expectation has been waiting for a worker (can't start working), used to request more resources */
waitingForWorkerTime: number | null
/** Timestamp to track how long the expectation has been waiting for a worker, used to restart to re-query for workers */
Expand Down Expand Up @@ -78,6 +83,10 @@ export function sortTrackedExpectations(
if (aHadRecentError && !bHadRecentError) return 1
if (!aHadRecentError && bHadRecentError) return -1

// Highest skipEvaluationCount first
if (a.skipEvaluationCount < b.skipEvaluationCount) return 1
if (a.skipEvaluationCount > b.skipEvaluationCount) return -1

// Lowest priority first
if (a.exp.priority > b.exp.priority) return 1
if (a.exp.priority < b.exp.priority) return -1
Expand Down Expand Up @@ -109,6 +118,7 @@ export function getDefaultTrackedExpectation(
tech: 'N/A (init)',
},
lastEvaluationTime: 0,
skipEvaluationCount: 0,
waitingForWorkerTime: null,
noWorkerAssignedTime: null,
errorCount: 0,
Expand Down

0 comments on commit 1b0246b

Please sign in to comment.