diff --git a/src/lib/app-helper.js b/src/lib/app-helper.js index 1fabf0ca..a323c2c6 100644 --- a/src/lib/app-helper.js +++ b/src/lib/app-helper.js @@ -314,24 +314,26 @@ async function downloadOWJar (url, outFile) { } /** @private */ -async function waitForOpenWhiskReadiness (host, endTime, period, timeout, waitFunc) { +async function waitForOpenWhiskReadiness (host, endTime, period, timeout, lastStatus, waitFunc) { if (Date.now() > endTime) { - throw new Error(`local openwhisk stack startup timed out: ${timeout}ms`) + throw new Error(`local openwhisk stack startup timed out after ${timeout}ms due to ${lastStatus}`) } - let ok + let ok, status try { const fetch = createFetch() const response = await fetch(host + '/api/v1') ok = response.ok + status = response.statusText } catch (e) { ok = false + status = e.toString() } if (!ok) { await waitFunc(period) - return waitForOpenWhiskReadiness(host, endTime, period, timeout, waitFunc) + return waitForOpenWhiskReadiness(host, endTime, period, timeout, status, waitFunc) } } @@ -349,7 +351,7 @@ async function runOpenWhiskJar (jarFile, runtimeConfigFile, apihost, waitInitTim const endTime = Date.now() + timeout await waitFor(waitInitTime) - await waitForOpenWhiskReadiness(apihost, endTime, waitPeriodTime, timeout, waitFor) + await waitForOpenWhiskReadiness(apihost, endTime, waitPeriodTime, timeout, null, waitFor) // must wrap in an object as execa return value is awaitable return { proc } diff --git a/test/commands/lib/app-helper.test.js b/test/commands/lib/app-helper.test.js index c424b7f2..cfc59a99 100644 --- a/test/commands/lib/app-helper.test.js +++ b/test/commands/lib/app-helper.test.js @@ -531,13 +531,14 @@ test('waitForOpenWhiskReadiness timeout', async () => { const period = 5000 const timeout = 5000 const endTime = Date.now() - 1000 // ends now + const status = 'FAIL' const waitFunc = jest.fn((_period) => { expect(_period).toEqual(period) }) - const result = appHelper.waitForOpenWhiskReadiness(host, endTime, period, timeout, waitFunc) + const result = appHelper.waitForOpenWhiskReadiness(host, endTime, period, timeout, status, waitFunc) - await expect(result).rejects.toEqual(new Error(`local openwhisk stack startup timed out: ${timeout}ms`)) + await expect(result).rejects.toEqual(new Error(`local openwhisk stack startup timed out after ${timeout}ms due to ${status}`)) expect(mockFetch).toHaveBeenCalledTimes(0) expect(waitFunc).toHaveBeenCalledTimes(0) }) @@ -547,6 +548,7 @@ test('waitForOpenWhiskReadiness (fail, retry, then success)', async () => { const period = 5000 const timeout = 5000 const endTime = Date.now() + 5000 + const status = null const waitFunc = jest.fn((_period) => { expect(_period).toEqual(period) @@ -555,7 +557,7 @@ test('waitForOpenWhiskReadiness (fail, retry, then success)', async () => { .mockRejectedValueOnce(new Error('some error')) // first fail (fetch exception) .mockRejectedValueOnce({ ok: false }) // second fail (response not ok) .mockResolvedValue({ ok: true }) // finally success - const result = appHelper.waitForOpenWhiskReadiness(host, endTime, period, timeout, waitFunc) + const result = appHelper.waitForOpenWhiskReadiness(host, endTime, period, timeout, status, waitFunc) await expect(result).resolves.not.toBeDefined() expect(mockFetch).toHaveBeenCalledTimes(3)