Skip to content

Commit

Permalink
fix(benchmark): Make benchmark checks more robust (#10761)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Sep 10, 2024
1 parent 17f160c commit 56ebeed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/@n8n/benchmark/scenarios/httpNode/httpNode.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ export default function () {

check(res, {
'is status 200': (r) => r.status === 200,
'http requests were OK': (r) =>
// Response body is an array of the request status codes made with HttpNodes
JSON.parse(r.body).every((request) => request.statusCode === 200),
'http requests were OK': (r) => {
if (r.status !== 200) return false;

try {
// Response body is an array of the request status codes made with HttpNodes
const body = JSON.parse(r.body);
return Array.isArray(body) ? body.every((request) => request.statusCode === 200) : false;
} catch (error) {
console.error('Error parsing response body: ', error);
return false;
}
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ export default function () {
const res = http.post(`${apiBaseUrl}/webhook/code-node-benchmark`, {});
check(res, {
'is status 200': (r) => r.status === 200,
'has items in response': (r) => JSON.parse(r.body).length === 5,
'has items in response': (r) => {
if (r.status !== 200) return false;

try {
const body = JSON.parse(r.body);
return Array.isArray(body) ? body.length === 5 : false;
} catch (error) {
console.error('Error parsing response body: ', error);
return false;
}
},
});
}

0 comments on commit 56ebeed

Please sign in to comment.