Skip to content

Commit c2c5dae

Browse files
feat: change respect workflow-level totalTimeMs calculation (#2322)
1 parent 9a74940 commit c2c5dae

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.changeset/twelve-birds-wonder.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/respect-core": minor
3+
"@redocly/cli": minor
4+
---
5+
6+
Adjusted the calculation of Respect's workflow-level `totalTimeMs` to sum the network request times of all steps.

packages/respect-core/src/modules/__tests__/flow-runner/runner/create-workflow-runner.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('runWorkflow', () => {
119119
filePath: fileName,
120120
logger,
121121
},
122+
executedSteps: [],
122123
} as unknown as TestContext;
123124

124125
await runWorkflow({ workflowInput: 'test', ctx, executedStepsCount: { value: 0 } });
@@ -298,6 +299,7 @@ describe('runWorkflow', () => {
298299
logger,
299300
},
300301
$outputs: {},
302+
executedSteps: [],
301303
} as unknown as TestContext;
302304

303305
await runWorkflow({ workflowInput: 'test', ctx, executedStepsCount: { value: 0 } });
@@ -352,6 +354,7 @@ describe('runWorkflow', () => {
352354
logger,
353355
},
354356
$outputs: {},
357+
executedSteps: [],
355358
} as unknown as TestContext;
356359

357360
await runWorkflow({

packages/respect-core/src/modules/flow-runner/runner.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
RunWorkflowInput,
2929
WorkflowExecutionResult,
3030
ExecutedStepsCount,
31+
Step,
3132
} from '../../types.js';
3233

3334
export async function runTestFile({
@@ -237,7 +238,7 @@ export async function runWorkflow({
237238
stepId: parentStepId,
238239
startTime: workflowStartTime,
239240
endTime,
240-
totalTimeMs: Math.ceil(endTime - workflowStartTime),
241+
totalTimeMs: calculateWorkflowTotalTimeMs(ctx.executedSteps),
241242
executedSteps: ctx.executedSteps,
242243
ctx,
243244
globalTimeoutError: hasFailedTimeoutSteps,
@@ -339,3 +340,23 @@ function findSourceDescriptionUrl(
339340
);
340341
}
341342
}
343+
344+
function isWorkflowExecutionResult(
345+
step: Step | WorkflowExecutionResult
346+
): step is WorkflowExecutionResult {
347+
return 'type' in step && step.type === 'workflow';
348+
}
349+
350+
function calculateWorkflowTotalTimeMs(executedSteps: (Step | WorkflowExecutionResult)[]) {
351+
let totalTime = 0;
352+
353+
for (const step of executedSteps) {
354+
if (isWorkflowExecutionResult(step)) {
355+
totalTime += step.totalTimeMs;
356+
} else {
357+
totalTime += step.response?.time || 0;
358+
}
359+
}
360+
361+
return totalTime;
362+
}

0 commit comments

Comments
 (0)