Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/respect/local-json-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fake-db.json
19 changes: 1 addition & 18 deletions __tests__/respect/local-json-server/fake-db.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
{
"items": [
{
"id": "a959",
"value": 9
},
{
"id": "1768",
"value": 6
},
{
"id": "6e43",
"value": 10
},
{
"id": "8cf3",
"value": 7
}
]
"items": []
}
165 changes: 165 additions & 0 deletions __tests__/respect/max-steps/__snapshots__/max-steps.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should quit an infinite loop on RESPECT_MAX_STEPS 1`] = `
"────────────────────────────────────────────────────────────────────────────────

Running workflow arazzo.yaml / infinite

✗ GET /ping - step pre-step

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action continue for the step pre-step

Running child workflow for the step with-nested
Running workflow arazzo.yaml / nested-workflow

✗ GET /ping - step step-1

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action next-step for the step step-1

✗ GET /ping - step step-2

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request



✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping

✗ GET /ping - step ping

    Request URL: https://bad-api-url.com/api/ping

    ✗ failed network request

Running failure action infinite-loop for the step ping










  Failed tests info:

  Workflow name: infinite

    stepId - pre-step
    ✗ failed network request
      fetch failed

    stepId - step-1
    ✗ failed network request
      fetch failed

    stepId - step-2
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ failed network request
      fetch failed

    stepId - ping
    ✗ unexpected error
    Reason: Max steps (10) reached
  Summary for arazzo.yaml

  Workflows: 1 failed, 1 total
  Steps: 11 failed, 11 total
  Checks: 11 failed, 11 total
  Time: <test>ms


┌─────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┬─────────┐
│ Filename │ Workflows │ Passed │ Failed │ Warnings │ Skipped │
├─────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┼─────────┤
│ x arazzo.yaml │ 1 │ 0 │ 1 │ - │ - │
└─────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┴─────────┘



Tests exited with error
"
`;
47 changes: 47 additions & 0 deletions __tests__/respect/max-steps/arazzo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
arazzo: 1.0.1
info:
title: Arazzo
version: 1.0.0
description: Test infinite loop
sourceDescriptions:
- name: oas
type: openapi
url: ./oas.yaml
workflows:
- workflowId: infinite
steps:
- stepId: pre-step
description: Pre-step
operationId: ping
onFailure:
- name: continue
type: goto
stepId: with-nested

- stepId: with-nested
description: With nested workflow
workflowId: nested-workflow

- stepId: ping
description: Ping the API
operationId: ping
onFailure:
- name: infinite-loop
type: goto
stepId: ping

- workflowId: nested-workflow
steps:
- stepId: step-1
description: Step 1
operationId: ping
onFailure:
- name: next-step
type: goto
stepId: step-2
- stepId: step-2
description: Step 2
operationId: ping
onFailure:
- name: end
type: end
20 changes: 20 additions & 0 deletions __tests__/respect/max-steps/max-steps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getParams, getCommandOutput } from '../utils';
import { join } from 'path';

test('should quit an infinite loop on RESPECT_MAX_STEPS', () => {
const indexEntryPoint = join(process.cwd(), 'packages/cli/lib/index.js');
const fixturesPath = join(__dirname, 'arazzo.yaml');
const args = getParams(indexEntryPoint, [
'respect',
fixturesPath,
'--verbose',
'--workflow',
'infinite',
]);

const result = getCommandOutput(args, {
RESPECT_MAX_STEPS: '10',
});

expect(result).toMatchSnapshot();
});
18 changes: 18 additions & 0 deletions __tests__/respect/max-steps/oas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
openapi: 3.1.0
info:
title: Arazzo
version: 1.0.0
description: Arazzo API
license:
name: MIT
servers:
- url: https://bad-api-url.com/api
paths:
/ping:
get:
security: []
summary: Ping
operationId: ping
responses:
'200':
description: A list of users
3 changes: 2 additions & 1 deletion __tests__/respect/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function getParams(indexEntryPoint: string, args: string[] = []): string[
return [indexEntryPoint, ...args];
}

export function getCommandOutput(args: string[]) {
export function getCommandOutput(args: string[], env?: Record<string, string>) {
const result = spawnSync('node', args, {
encoding: 'utf-8',
stdio: 'pipe',
Expand All @@ -16,6 +16,7 @@ export function getCommandOutput(args: string[]) {
NODE_ENV: 'test',
NO_COLOR: 'TRUE',
FORCE_COLOR: '0',
...env,
},
});

Expand Down
14 changes: 9 additions & 5 deletions packages/respect-core/src/handlers/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
if (jsonOutputFile) {
writeFileSync(
jsonOutputFile,
JSON.stringify({
files: composeJsonLogsFiles(runAllFilesResult),
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
totalTime: performance.now() - startedAt,
} as JsonLogs),
JSON.stringify(
{
files: composeJsonLogsFiles(runAllFilesResult),
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
totalTime: performance.now() - startedAt,
} as JsonLogs,
null,
2
),
'utf-8'
);
logger.log(blue(indent(`JSON logs saved in ${green(jsonOutputFile)}`, 2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ describe('runStep', () => {
});

expect(displayChecks).toHaveBeenCalled();
expect(checkCriteria).toHaveBeenCalledTimes(5);
expect(checkCriteria).toHaveBeenCalledTimes(3);
});

it('should result with an error when onFailure step criteria with retry StepId and WorkflowId provided', async () => {
Expand Down Expand Up @@ -1790,7 +1790,7 @@ describe('runStep', () => {
});

expect(displayChecks).toHaveBeenCalled();
expect(checkCriteria).toHaveBeenCalledTimes(5);
expect(checkCriteria).toHaveBeenCalledTimes(3);
});

it('should execute onFailure step criteria with successful retry', async () => {
Expand Down
Loading
Loading