From 34c287b39dac3a8090638b13db6677bd8e7ee3d5 Mon Sep 17 00:00:00 2001 From: bailey Date: Mon, 30 Jun 2025 11:08:35 -0600 Subject: [PATCH 1/2] fix flaky tests? --- test/integration/auth/auth.prose.test.ts | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/integration/auth/auth.prose.test.ts b/test/integration/auth/auth.prose.test.ts index 3bf068dbb91..e0cd0b81e2d 100644 --- a/test/integration/auth/auth.prose.test.ts +++ b/test/integration/auth/auth.prose.test.ts @@ -9,8 +9,6 @@ function makeConnectionString(config, username, password) { const metadata: MongoDBMetadataUI = { requires: { - auth: 'enabled', - mongodb: '>=3.7.3', predicate: () => process.env.LOAD_BALANCER ? 'TODO(NODE-5631): fix tests to run in load balancer mode.' : true } @@ -305,8 +303,7 @@ describe('Authentication Spec Prose Tests', function () { ); }); - // TODO(NODE-6752): Fix flaky SCRAM-SHA-256 tests - describe.skip('Step 4', function () { + describe('Step 4', function () { /** * Step 4 * To test SASLprep behavior, create two users: @@ -343,11 +340,9 @@ describe('Authentication Spec Prose Tests', function () { utilClient = this.configuration.newClient(this.configuration.url()); const db = utilClient.db('admin'); - try { - await Promise.all(users.map(user => db.removeUser(user.username))); - } catch { - /** We ensure that users are deleted. No action needed. */ - } + // We do not care if this fails - this is just cleanup for any + // previous test iterations or previous test runs. + await Promise.allSettled(users.map(user => db.removeUser(user.username))); const createUserCommands = users.map(user => ({ createUser: user.username, @@ -356,7 +351,15 @@ describe('Authentication Spec Prose Tests', function () { mechanisms: user.mechanisms })); - await Promise.all(createUserCommands.map(cmd => db.command(cmd))); + const failures = await Promise.allSettled( + createUserCommands.map(cmd => db.command(cmd)) + ).then(resolutions => resolutions.filter(resolution => resolution.status === 'rejected')); + + if (failures.length) { + throw new Error( + 'Error(s) creating users: ' + failures.map(failure => failure.reason).join(' | ') + ); + } }); afterEach(async function () { @@ -391,7 +394,7 @@ describe('Authentication Spec Prose Tests', function () { const stats = await client.db('admin').stats(); expect(stats).to.exist; } - ).skipReason = 'TODO(NODE-6752): Fix flaky SCRAM-SHA-256 test'; + ); it( 'logs in with normalized username and non-normalized password', From ae3c3ef403df09da402c9788d09846ce3e075810 Mon Sep 17 00:00:00 2001 From: bailey Date: Mon, 30 Jun 2025 11:28:59 -0600 Subject: [PATCH 2/2] make users in a before/after hook --- test/integration/auth/auth.prose.test.ts | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/test/integration/auth/auth.prose.test.ts b/test/integration/auth/auth.prose.test.ts index e0cd0b81e2d..d9408a42001 100644 --- a/test/integration/auth/auth.prose.test.ts +++ b/test/integration/auth/auth.prose.test.ts @@ -2,6 +2,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { Connection, LEGACY_HELLO_COMMAND, type MongoClient, ScramSHA256 } from '../../mongodb'; +import { type TestConfiguration } from '../../tools/runner/config'; function makeConnectionString(config, username, password) { return `mongodb://${username}:${password}@${config.host}:${config.port}/admin?`; @@ -321,7 +322,6 @@ describe('Authentication Spec Prose Tests', function () { * mongodb://%E2%85%A8:IV\@mongodb.example.com/admin * mongodb://%E2%85%A8:I%C2%ADV\@mongodb.example.com/admin */ - let utilClient: MongoClient; let client: MongoClient; const users = [ { @@ -336,14 +336,19 @@ describe('Authentication Spec Prose Tests', function () { } ]; - beforeEach(async function () { - utilClient = this.configuration.newClient(this.configuration.url()); + async function cleanUpUsers(configuration: TestConfiguration) { + const utilClient = configuration.newClient(); const db = utilClient.db('admin'); - // We do not care if this fails - this is just cleanup for any - // previous test iterations or previous test runs. await Promise.allSettled(users.map(user => db.removeUser(user.username))); + await utilClient.close(); + } + + async function createUsers(configuration: TestConfiguration) { + const utilClient = configuration.newClient(); + const db = utilClient.db('admin'); + const createUserCommands = users.map(user => ({ createUser: user.username, pwd: user.password, @@ -355,15 +360,25 @@ describe('Authentication Spec Prose Tests', function () { createUserCommands.map(cmd => db.command(cmd)) ).then(resolutions => resolutions.filter(resolution => resolution.status === 'rejected')); + await utilClient.close(); + if (failures.length) { throw new Error( 'Error(s) creating users: ' + failures.map(failure => failure.reason).join(' | ') ); } + } + + before(async function () { + await cleanUpUsers(this.configuration); + await createUsers(this.configuration); + }); + + after(function () { + return cleanUpUsers(this.configuration); }); afterEach(async function () { - await utilClient?.close(); await client?.close(); });