fix(benchmark): Make benchmark checks more robust (#10761)

This commit is contained in:
Tomi Turtiainen 2024-09-10 18:15:21 +03:00 committed by GitHub
parent 17f160ce96
commit 56ebeed880
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 4 deletions

View file

@ -8,8 +8,17 @@ export default function () {
check(res, {
'is status 200': (r) => r.status === 200,
'http requests were OK': (r) =>
'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
JSON.parse(r.body).every((request) => request.statusCode === 200),
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;
}
},
});
}

View file

@ -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;
}
},
});
}