some errors can specify retries (#11581)

Trying a different approach to retrying errors when logs must contain a value.

Alternative to: https://github.com/vercel/vercel/pull/11577
This commit is contained in:
Sean Massa
2024-05-10 17:19:10 -05:00
committed by GitHub
parent bc5fd41158
commit 722adf0e10
2 changed files with 13 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
---
some errors can specify retries

View File

@@ -122,9 +122,11 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
deploymentLogs,
logLength: deploymentLogs?.length,
});
throw new Error(
const error = new Error(
`Expected deployment logs of ${deploymentId} to contain ${toCheck}, it was not found`
);
error.retries = 20;
throw error;
} else {
logWithinTest('finished testing', JSON.stringify(probe));
return;
@@ -442,18 +444,19 @@ async function testDeployment(fixturePath, opts = {}) {
try {
await runProbe(probe, deploymentId, deploymentUrl, probeCtx);
} catch (err) {
if (!probe.retries) {
const retries = Math.max(probe.retries || 0, err.retries || 0);
if (!retries) {
throw err;
}
for (let i = 0; i < probe.retries; i++) {
logWithinTest(`re-trying ${i + 1}/${probe.retries}:`, stringifiedProbe);
for (let i = 0; i < retries; i++) {
logWithinTest(`re-trying ${i + 1}/${retries}:`, stringifiedProbe);
try {
await runProbe(probe, deploymentId, deploymentUrl, probeCtx);
break;
} catch (err) {
if (i === probe.retries - 1) {
if (i === retries - 1) {
throw err;
}