From 86405be3313631f19845232f0de282b1596729d3 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 22 Nov 2024 10:05:12 -0500 Subject: [PATCH 1/5] fix problem --- .../credentials/sso/ssoAccessTokenProvider.test.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts index 1bde91b26d8..5ec63685ee5 100644 --- a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts +++ b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts @@ -310,13 +310,6 @@ describe('SsoAccessTokenProvider', function () { }) it('respects the device authorization expiration time', async function () { - // XXX: Don't know how to fix this "unhandled rejection" caused by this test: - // rejected promise not handled within 1 second: Error: Timed-out waiting for browser login flow to complete - // at poll (…/src/auth/sso/ssoAccessTokenProvider.ts:251:15) - // at async SsoAccessTokenProvider.authorize (…/src/auth/sso/ssoAccessTokenProvider.ts:188:23) - // at async SsoAccessTokenProvider.runFlow (…/src/auth/sso/ssoAccessTokenProvider.ts:113:20) - // at async SsoAccessTokenProvider.createToken (…/src/auth/sso/ssoAccessTokenProvider.ts:102:24) - setupFlow() stubOpen() const exception = new AuthorizationPendingException({ message: '', $metadata: {} }) @@ -324,13 +317,15 @@ describe('SsoAccessTokenProvider', function () { oidcClient.createToken.rejects(exception) oidcClient.startDeviceAuthorization.resolves(authorization) - const resp = sut.createToken() + sut.createToken() + .then(() => assert.fail('Should not resolve')) + .catch((e) => assert.ok(e instanceof ToolkitError)) + const progress = await getTestWindow().waitForMessage(/login page opened/i) await clock.tickAsync(750) assert.ok(progress.visible) await clock.tickAsync(750) assert.ok(!progress.visible) - await assert.rejects(resp, ToolkitError) assertTelemetry('aws_loginWithBrowser', { result: 'Failed', isReAuth: undefined, From 9a9635307e3db3a14383038ebcca627949a1a7cf Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 22 Nov 2024 10:42:16 -0500 Subject: [PATCH 2/5] add await to ensure promise resolves before test ends --- .../test/credentials/sso/ssoAccessTokenProvider.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts index 5ec63685ee5..e7b84fa9957 100644 --- a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts +++ b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts @@ -13,7 +13,7 @@ import { getCache } from '../../../auth/sso/cache' import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities' import { ClientRegistration, SsoProfile, SsoToken, proceedToBrowser } from '../../../auth/sso/model' import { OidcClient } from '../../../auth/sso/clients' -import { CancellationError } from '../../../shared/utilities/timeoutUtils' +import { CancellationError, sleep } from '../../../shared/utilities/timeoutUtils' import { AuthorizationPendingException, InternalServerException, @@ -81,8 +81,9 @@ describe('SsoAccessTokenProvider', function () { clock = installFakeClock() }) - after(function () { + after(async function () { clock.uninstall() + await sleep(3000) }) beforeEach(async function () { @@ -317,7 +318,8 @@ describe('SsoAccessTokenProvider', function () { oidcClient.createToken.rejects(exception) oidcClient.startDeviceAuthorization.resolves(authorization) - sut.createToken() + const resp = sut + .createToken() .then(() => assert.fail('Should not resolve')) .catch((e) => assert.ok(e instanceof ToolkitError)) @@ -331,6 +333,7 @@ describe('SsoAccessTokenProvider', function () { isReAuth: undefined, credentialStartUrl: startUrl, }) + await resp }) /** From 1fb2337e50028b6d4722dadbd5bbb8e3af57e7e9 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 22 Nov 2024 12:15:27 -0500 Subject: [PATCH 3/5] remove sleep --- .../src/test/credentials/sso/ssoAccessTokenProvider.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts index e7b84fa9957..c54c9673da2 100644 --- a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts +++ b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts @@ -13,7 +13,7 @@ import { getCache } from '../../../auth/sso/cache' import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities' import { ClientRegistration, SsoProfile, SsoToken, proceedToBrowser } from '../../../auth/sso/model' import { OidcClient } from '../../../auth/sso/clients' -import { CancellationError, sleep } from '../../../shared/utilities/timeoutUtils' +import { CancellationError } from '../../../shared/utilities/timeoutUtils' import { AuthorizationPendingException, InternalServerException, @@ -81,9 +81,8 @@ describe('SsoAccessTokenProvider', function () { clock = installFakeClock() }) - after(async function () { + after(function () { clock.uninstall() - await sleep(3000) }) beforeEach(async function () { From 1547c7f7b50786b3f25c363d84e7dca9bc1a956e Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 22 Nov 2024 17:20:51 -0500 Subject: [PATCH 4/5] move await before telemetry assertion to avoid race cond --- .../test/credentials/sso/ssoAccessTokenProvider.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts index c54c9673da2..b662556e0aa 100644 --- a/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts +++ b/packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts @@ -320,19 +320,24 @@ describe('SsoAccessTokenProvider', function () { const resp = sut .createToken() .then(() => assert.fail('Should not resolve')) - .catch((e) => assert.ok(e instanceof ToolkitError)) + .catch((e) => { + assert.ok( + e instanceof ToolkitError && + e.message === 'Timed-out waiting for browser login flow to complete' + ) + }) const progress = await getTestWindow().waitForMessage(/login page opened/i) await clock.tickAsync(750) assert.ok(progress.visible) await clock.tickAsync(750) assert.ok(!progress.visible) + await resp assertTelemetry('aws_loginWithBrowser', { result: 'Failed', isReAuth: undefined, credentialStartUrl: startUrl, }) - await resp }) /** From c57c0fae6f553f1b4cdaed2ed8c84a118eef5f6f Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 29 Nov 2024 12:19:18 -0500 Subject: [PATCH 5/5] remove pattern --- buildspec/shared/common.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildspec/shared/common.sh b/buildspec/shared/common.sh index 704f97799d8..8144399370f 100644 --- a/buildspec/shared/common.sh +++ b/buildspec/shared/common.sh @@ -5,11 +5,10 @@ # . buildspec/shared/common.sh # Ignore these patterns when deciding if the build should fail. -# - "waiting for browser": from `ssoAccessTokenProvider.test.ts`, unclear how to fix it. # - "Webview is disposed": only happens on vscode "minimum" (1.68.0) # - "HTTPError: Response code …": caused by github rate-limiting. # - "npm WARN deprecated querystring": transitive dep of aws sdk v2 (check `npm ls querystring`), so that's blocked until we migrate to v3. -_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring\|npm WARN deprecated' +_ignore_pat='HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring\|npm WARN deprecated' if [ "$VSCODE_TEST_VERSION" = 'minimum' ]; then _ignore_pat="$_ignore_pat"'\|Webview is disposed' fi