From 3c289a5510b54f755af47153faeb9a2029c67f23 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 3 Mar 2020 13:32:32 -0800 Subject: [PATCH] feat: add ECONNREFUSED to list of known errors for isAvailable() --- src/index.ts | 1 + test/index.test.ts | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index e68e0b0..5127e39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -203,6 +203,7 @@ export async function isAvailable() { 'ENETUNREACH', 'ENOENT', 'ENOTFOUND', + 'ECONNREFUSED', ].includes(err.code) ) { // Failure to resolve the metadata service means that it is not available. diff --git a/test/index.test.ts b/test/index.test.ts index 645a34a..b12e557 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -244,20 +244,25 @@ it('should log error if DEBUG_AUTH is set', async () => { assert.strictEqual(/failed, reason/.test(err!.message), true); }); -['EHOSTDOWN', 'EHOSTUNREACH', 'ENETUNREACH', 'ENOENT', 'ENOTFOUND'].forEach( - errorCode => { - it(`should fail fast on isAvailable if ${errorCode} is returned`, async () => { - const secondary = secondaryHostRequest(500); - const primary = nock(HOST) - .get(`${PATH}/${TYPE}`) - .replyWithError({code: errorCode}); - const isGCE = await gcp.isAvailable(); - await secondary; - primary.done(); - assert.strictEqual(false, isGCE); - }); - } -); +[ + 'EHOSTDOWN', + 'EHOSTUNREACH', + 'ENETUNREACH', + 'ENOENT', + 'ENOTFOUND', + 'ECONNREFUSED', +].forEach(errorCode => { + it(`should fail fast on isAvailable if ${errorCode} is returned`, async () => { + const secondary = secondaryHostRequest(500); + const primary = nock(HOST) + .get(`${PATH}/${TYPE}`) + .replyWithError({code: errorCode}); + const isGCE = await gcp.isAvailable(); + await secondary; + primary.done(); + assert.strictEqual(false, isGCE); + }); +}); it(`should fail fast on isAvailable if 404 status code is returned`, async () => { const secondary = secondaryHostRequest(500);