Skip to content

Commit

Permalink
fix(cli): remove worker error message when expect errors in workers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge authored Jun 10, 2024
1 parent 10da198 commit c49887b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/artillery-plugin-expect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function expectationsPluginCheckExpectations(
}

if (global.artillery) {
global.artillery.suggestedExitCode = 1;
global.artillery.suggestedExitCode = 21;
}

if (userContext.expectationsPlugin.reportFailuresAsErrors) {
Expand Down
13 changes: 8 additions & 5 deletions packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -1917,11 +1917,14 @@ async function listen(context, ee) {
)
);
}
artillery.log(
chalk.yellow(
`Worker exited with an error, worker ID = ${attrs.workerId.StringValue}`
)
);
if (body.exitCode != 21) {
artillery.log(
chalk.yellow(
`Worker exited with an error, worker ID = ${attrs.workerId.StringValue}`
)
);
}

// TODO: Copy log over and print path to log file so that user may inspect it - in a temporary location
global.artillery.suggestedExitCode = body.exitCode || 1;
});
Expand Down
3 changes: 3 additions & 0 deletions packages/artillery/lib/platform/aws-ecs/worker/loadgen-worker
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare -r ERR_INTERRUPTED=7
declare -r ERR_UNKNOWN_PLATFORM=8
declare -r ERR_DEP=9
declare -r ERR_DEP_INSTALL=10 # npm install / yarn install failed
declare -r ERR_CLI_ERROR_EXPECT=21

ERR_EXTRA_INFO=""

Expand Down Expand Up @@ -314,6 +315,8 @@ run_a9 () {

if [[ $CLI_STATUS -eq 0 ]] ; then
EXIT_CODE=0
elif [[ $CLI_STATUS -eq $ERR_CLI_ERROR_EXPECT ]] ; then
EXIT_CODE=$ERR_CLI_ERROR_EXPECT
else
EXIT_CODE=$ERR_CLI_ERROR
fi
Expand Down
20 changes: 11 additions & 9 deletions packages/artillery/lib/platform/aws-lambda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,17 @@ class PlatformLambda {
} else if (body.event === 'workerError') {
global.artillery.suggestedExitCode = body.exitCode || 1;

this.events.emit(body.event, workerId, {
id: workerId,
error: new Error(
`A Lambda function has exited with an error. Reason: ${body.reason}`
),
level: 'error',
aggregatable: false,
logs: body.logs
});
if (body.exitCode != 21) {
this.events.emit(body.event, workerId, {
id: workerId,
error: new Error(
`A Lambda function has exited with an error. Reason: ${body.reason}`
),
level: 'error',
aggregatable: false,
logs: body.logs
});
}
} else if (body.event == 'workerReady') {
this.events.emit(body.event, workerId);
this.waitingReadyCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ test('CLI should exit with non-zero exit code when there are failed expectations
await $`${A9_PATH} run-fargate ${__dirname}/fixtures/cli-exit-conditions/with-expect.yml --record --tags ${baseTags} --output ${reportFilePath} --count 2`;
t.fail(`Test "${t.name}" - Should have had non-zero exit code.`);
} catch (output) {
t.equal(output.exitCode, 6, 'CLI Exit Code should be 6');
t.equal(output.exitCode, 21, 'CLI Exit Code should be 21');

t.ok(
!output.stderr.includes('Worker exited with an error'),
'Should not have worker exit error message in stdout'
);

const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
t.equal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ tap.test(
await $`${A9_PATH} run-lambda ${__dirname}/../fargate/fixtures/cli-exit-conditions/with-expect.yml --architecture x86_64 --record --tags ${tags} --output ${reportFilePath} --count 2`;
t.fail(`Test "${t.name}" - Should have had non-zero exit code.`);
} catch (output) {
t.equal(output.exitCode, 1, 'CLI Exit Code should be 1');
t.equal(output.exitCode, 21, 'CLI Exit Code should be 21');
t.ok(
!output.stderr.includes('Worker exited with an error'),
'Should not have worker exit error message in stdout'
);

const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
t.equal(
Expand Down

0 comments on commit c49887b

Please sign in to comment.