Skip to content

Commit be6e10d

Browse files
refactor hooks - final test hopefully
1 parent 9236777 commit be6e10d

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

test/integration/client-side-encryption/client_side_encryption.prose.deadlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function deadlockTests(_metadata) {
9393
const metadata = { ..._metadata, requires: { ..._metadata.requires, auth: 'disabled' } };
9494
metadata.skipReason = 'TODO: NODE-3891 - fix tests broken when AUTH enabled';
9595
describe('Connection Pool Deadlock Prevention', function () {
96-
installNodeDNSWorkaroundHooks('beforeEach');
96+
installNodeDNSWorkaroundHooks();
9797
beforeEach(function () {
9898
try {
9999
const mongodbClientEncryption = this.configuration.mongodbClientEncryption;

test/integration/client-side-encryption/client_side_encryption.prose.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
7070
'base64'
7171
);
7272

73-
installNodeDNSWorkaroundHooks('before');
73+
installNodeDNSWorkaroundHooks();
7474

7575
describe('Data key and double encryption', function () {
7676
// Data key and double encryption

test/integration/client-side-encryption/client_side_encryption.spec.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Client Side Encryption (Legacy)', function () {
7373
testContext
7474
);
7575

76-
installNodeDNSWorkaroundHooks('before');
76+
installNodeDNSWorkaroundHooks();
7777
after(() => testContext.teardown());
7878
before(function () {
7979
return testContext.setup(this.configuration);
@@ -97,7 +97,7 @@ describe('Client Side Encryption (Legacy)', function () {
9797
});
9898

9999
describe('Client Side Encryption (Unified)', function () {
100-
installNodeDNSWorkaroundHooks('before');
100+
installNodeDNSWorkaroundHooks();
101101
runUnifiedSuite(loadSpecTests(path.join('client-side-encryption', 'tests', 'unified')), () =>
102102
isServerless ? 'Unified CSFLE tests to not run on serverless' : false
103103
);

test/integration/client-side-encryption/driver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('Client Side Encryption Functional', function () {
2222
const keyVaultCollName = 'datakeys';
2323
const keyVaultNamespace = `${keyVaultDbName}.${keyVaultCollName}`;
2424

25-
installNodeDNSWorkaroundHooks('before');
25+
installNodeDNSWorkaroundHooks();
2626

2727
it('CSFLE_KMS_PROVIDERS should be valid EJSON', function () {
2828
const CSFLE_KMS_PROVIDERS = process.env.CSFLE_KMS_PROVIDERS;

test/manual/atlas-data-lake-testing/atlas_data_lake_testing.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Atlas Data Lake - spec', function () {
2323
// These tests timeout connecting to on localhost mongohoused in CI on Node18+.
2424
// Manually setting the ip address resolution is safe for testing purposes
2525
// because in production, mongohoused will never be running on localhost.
26-
installNodeDNSWorkaroundHooks('before');
26+
installNodeDNSWorkaroundHooks();
2727

2828
before(function () {
2929
return testContext.setup(this.configuration);

test/manual/socks5.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Socks5 Connectivity', function () {
3535
rsConnectionString.searchParams.set('serverSelectionTimeoutMS', '2000');
3636
singleConnectionString.searchParams.set('serverSelectionTimeoutMS', '2000');
3737

38-
installNodeDNSWorkaroundHooks('before');
38+
installNodeDNSWorkaroundHooks();
3939

4040
context((proxyUsername ? 'with' : 'without') + ' Socks5 auth required', function () {
4141
context('with missing required Socks5 auth configuration', function () {

test/tools/runner/hooks/configuration.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,38 +171,29 @@ const beforeAllPluginImports = () => {
171171
};
172172

173173
/**
174-
* @param {'beforeEach' | 'before'} type
175-
*
176174
* @remarks TODO(NODE-4884): once happy eyeballs support is added, we no longer need to set
177175
* the default dns resolution order for CI
178176
*/
179-
function installNodeDNSWorkaroundHooks(type) {
180-
const isAffectedNodeVersion =
177+
function installNodeDNSWorkaroundHooks() {
178+
if (
181179
process.version.startsWith('v18') ||
182180
process.version.startsWith('v19') ||
183-
process.version.startsWith('v20');
184-
185-
if (!isAffectedNodeVersion || !['before', 'beforeEach'].includes(type)) {
186-
return;
181+
process.version.startsWith('v20')
182+
) {
183+
// We set before hooks because some tests connect in before hooks
184+
before(() => {
185+
setDefaultResultOrder('ipv4first');
186+
});
187+
188+
// We set beforeEach hooks to make this resilient to test ordering and
189+
// ensure each affected test has the correct ip address resolution setting
190+
beforeEach(() => {
191+
setDefaultResultOrder('ipv4first');
192+
});
193+
afterEach(() => {
194+
setDefaultResultOrder('verbatim');
195+
});
187196
}
188-
189-
// if (type === 'beforeEach') {
190-
beforeEach(() => {
191-
setDefaultResultOrder('ipv4first');
192-
});
193-
afterEach(() => {
194-
setDefaultResultOrder('verbatim');
195-
});
196-
// } else if (type === 'before') {
197-
// before(() => {
198-
// console.error(source, 'setting dns resolution ordering');
199-
// setDefaultResultOrder('ipv4first');
200-
// });
201-
// after(() => {
202-
// console.error(source, 'set back to verbatim');
203-
// setDefaultResultOrder('verbatim');
204-
// });
205-
// }
206197
}
207198

208199
module.exports = {

0 commit comments

Comments
 (0)