Skip to content

Commit c8bfe2f

Browse files
authored
test(flaky): fix unresolved promise causing linux failures (#6088)
## Problem #6043 To reproduce, add a 5 second delay to the `after` hook at the top level. One way to do this is to insert this at line 84. ``` after(async function () { clock.uninstall() await sleep(5000) }) ``` Despite asserting that the promise rejects within the test, the promise rejects after the test as well. Not entirely sure why this happening. - Tried manually wrapping in try-catch with an `await` instead of `assert.rejects` and it still fails. - Tried wrapping the promise in another promise before passing to `assert.rejects`. ## Solution What does appear to work, is manually handling the callback of the promise. That is, explicitly defining a `then` and `catch` method to assert the rejection, and awaiting the promise at the end of the test to ensure it resolves before the test finishes. Not sure why this works, but I am unable to reproduce the error with this change. ## Notes - `assert.rejects` implementation: https://github.com/nodejs/node/blob/3178a762d6a2b1a37b74f02266eea0f3d86603be/lib/assert.js#L653. Doesn't appear to be the problem because the same is observed when manually wrapping. - `await` docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2905eb8 commit c8bfe2f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

buildspec/shared/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# - "waiting for browser": from `ssoAccessTokenProvider.test.ts`, unclear how to fix it.
99
# - "HTTPError: Response code …": caused by github rate-limiting.
1010
# - "npm WARN deprecated querystring": transitive dep of aws sdk v2 (check `npm ls querystring`), so that's blocked until we migrate to v3.
11-
_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring\|npm WARN deprecated'
11+
_ignore_pat='HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring\|npm WARN deprecated'
1212

1313
# Do not print (noisy) lines matching these patterns.
1414
# - "ERROR:bus… Failed to connect to the bus": noise related to "xvfb". https://github.com/cypress-io/cypress/issues/19299

packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,27 +310,29 @@ describe('SsoAccessTokenProvider', function () {
310310
})
311311

312312
it('respects the device authorization expiration time', async function () {
313-
// XXX: Don't know how to fix this "unhandled rejection" caused by this test:
314-
// rejected promise not handled within 1 second: Error: Timed-out waiting for browser login flow to complete
315-
// at poll (…/src/auth/sso/ssoAccessTokenProvider.ts:251:15)
316-
// at async SsoAccessTokenProvider.authorize (…/src/auth/sso/ssoAccessTokenProvider.ts:188:23)
317-
// at async SsoAccessTokenProvider.runFlow (…/src/auth/sso/ssoAccessTokenProvider.ts:113:20)
318-
// at async SsoAccessTokenProvider.createToken (…/src/auth/sso/ssoAccessTokenProvider.ts:102:24)
319-
320313
setupFlow()
321314
stubOpen()
322315
const exception = new AuthorizationPendingException({ message: '', $metadata: {} })
323316
const authorization = createAuthorization(1000)
324317
oidcClient.createToken.rejects(exception)
325318
oidcClient.startDeviceAuthorization.resolves(authorization)
326319

327-
const resp = sut.createToken()
320+
const resp = sut
321+
.createToken()
322+
.then(() => assert.fail('Should not resolve'))
323+
.catch((e) => {
324+
assert.ok(
325+
e instanceof ToolkitError &&
326+
e.message === 'Timed-out waiting for browser login flow to complete'
327+
)
328+
})
329+
328330
const progress = await getTestWindow().waitForMessage(/login page opened/i)
329331
await clock.tickAsync(750)
330332
assert.ok(progress.visible)
331333
await clock.tickAsync(750)
332334
assert.ok(!progress.visible)
333-
await assert.rejects(resp, ToolkitError)
335+
await resp
334336
assertTelemetry('aws_loginWithBrowser', {
335337
result: 'Failed',
336338
isReAuth: undefined,

0 commit comments

Comments
 (0)