diff --git a/src/utils.test.ts b/src/utils.test.ts index e53f926a..58866118 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -52,6 +52,15 @@ describe('utils', () => { await expect(res).to.eventually.be.fulfilled }) + it('should reset confirmation counter', async () => { + const stub = sandbox.stub(fetch, 'Promise').returns(successResp) + const confirmations = 3 + const res = waitTillAvailable(url, { confirmations }) + await tick(confirmations + 2) // wait extra rounds + expect(stub).to.have.callCount(confirmations) + await expect(res).to.eventually.be.fulfilled + }) + it('should bail when a request returns an unexpected status code', async () => { const stub = sandbox.stub(fetch, 'Promise').returns(failResp) const retries = 3 diff --git a/src/utils.ts b/src/utils.ts index 00b5ba26..afca4f4a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -97,6 +97,7 @@ export const waitTillAvailable = async (url: string, opts?: WaitTillAvailableOpt try { const res = await fetch(url, fetchOptions) if (res.status !== options.status) { + confirmations = 0 console.warn(`GET ${url} ${res.status} !== ${options.status}`) const err = new Error(`Wrong status code: ${res.status}`) // if we get a 404 or 503 we know some changes in either nginx or istio might still not be ready @@ -112,6 +113,7 @@ export const waitTillAvailable = async (url: string, opts?: WaitTillAvailableOpt } } catch (e) { // Print system errors like ECONNREFUSED + confirmations = 0 console.error(`Error in try #${attempt}: `, e.message) if (options.retries !== 0 && attempt === options.retries!) { bail(new Error(`Max retries (${options.retries}) has been reached!`))