Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
due to this change one of the tests needed a slight update to work again due
to a race condition that occurs during testing since we do not know when all
the required event emitters are fully completed.

In this case the onDidDeleteConnection event handler in SecondaryAuth was async
and the unit test completed before the handler finished. This caused the test to fail.

Signed-off-by: nkomonen-amazon <[email protected]>
  • Loading branch information
nkomonen-amazon committed Sep 13, 2024
1 parent 1c03003 commit bbeb410
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/test/credentials/secondaryAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createBuilderIdProfile, createTestAuth } from './testUtil'
import { Connection, createSsoProfile, hasScopes, isSsoConnection } from '../../auth/connection'
import assert from 'assert'
import globals from '../../shared/extensionGlobals'
import { waitUntil } from '../../shared/utilities/timeoutUtils'

describe('SecondaryAuth', function () {
let auth: ReturnType<typeof createTestAuth>
Expand Down Expand Up @@ -100,8 +101,13 @@ describe('SecondaryAuth', function () {
// delete SecondaryAuth
await auth.deleteConnection(conn)

// currently both Auth onDidChangeConnectionState and onDidDeleteConnection trigger
// and we need to wait for both of the callbacks defined through them in SecondaryAuth to complete.
// We know they all completed when SecondaryAuth.onDidChangeActiveConnection has been called twice
await waitUntil(async () => onDidChangeActiveConnection.callCount === 2, { interval: 10, timeout: 10000 })

// we fallback to the PrimaryAuth connection
assert.strictEqual(onDidChangeActiveConnection.called, true)
assert.strictEqual(onDidChangeActiveConnection.callCount, 2)
assert.deepStrictEqual(
{
id: secondaryAuth.activeConnection?.id,
Expand Down

0 comments on commit bbeb410

Please sign in to comment.