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