Skip to content

Commit c5765b5

Browse files
author
Kyle Keating
committed
Add retry feature when reporting test results
If the POST request to the testing service fails, wait 3 seconds and retry. Continue to retry up to 10 times before giving up. This should help reduce the number of tests that fail after they have started. If the POST request to the testing service fails, wait 3 seconds and retry. Continue to retry up to 10 times before giving up. This should help reduce the number of tests that fail after they have started.
1 parent 01c4936 commit c5765b5

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/RapidTest.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,42 @@ async function executeTest(testExecution, locationDetails) {
4949
headers["x-location-context"] = locationDetails.locationContext;
5050
}
5151

52-
await axios.post(
53-
// eslint-disable-next-line
54-
`${locationDetails.baseUrl}/api/location/${locationDetails.locationKey}/execution/${testExecution.testExecution.id}`,
55-
{
56-
result: testResult,
57-
api: testExecution.test.api,
58-
apiParentOwnerId: testExecution.apiParentOwnerId,
59-
},
60-
{
61-
headers,
62-
timeout: 15000,
63-
}
64-
);
52+
// Send the request back to the testing service, but retry up to 10 times if it fails.
53+
async function reportTestResult() {
54+
return new Promise((resolve, reject) => {
55+
let retry = 1;
56+
const interval = setInterval(async () => {
57+
try {
58+
await axios.post(
59+
// eslint-disable-next-line
60+
`${locationDetails.baseUrl}/api/location/${locationDetails.locationKey}/execution/${testExecution.testExecution.id}`,
61+
{
62+
result: testResult,
63+
api: testExecution.test.api,
64+
apiParentOwnerId: testExecution.apiParentOwnerId,
65+
},
66+
{
67+
headers,
68+
timeout: 15000,
69+
}
70+
);
71+
clearInterval(interval);
72+
resolve();
73+
} catch (e) {
74+
if (retry >= 10) {
75+
clearInterval(interval);
76+
reject(`Failed to report test execution ${testExecution.testExecution.id} (${retry}) times. Giving up.`);
77+
} else {
78+
consola.warn(
79+
`Failed to report test execution ${testExecution.testExecution.id} (${retry}) times. Retrying...`
80+
);
81+
retry += 1;
82+
}
83+
}
84+
}, 3000);
85+
});
86+
}
87+
await reportTestResult();
6588
}
6689

6790
async function fetchAndExecuteTests({ baseUrl, locationSecret, locationKey, locationContext, batchSize, logging }) {

0 commit comments

Comments
 (0)