Skip to content

Commit c919fcc

Browse files
asdf
1 parent d4b8084 commit c919fcc

File tree

7 files changed

+59
-97
lines changed

7 files changed

+59
-97
lines changed

.evergreen/run-alpine-fle-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
source secrets-export.sh
44

5+
export ALPINE=true
56
npm run check:csfle

etc/docker.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ docker buildx create --name builder --bootstrap --use
7777
RUN_WITH_MONGOCRYPTD=true bash .evergreen/setup-fle.sh
7878

7979
./mongodb/bin/mongocryptd --fork --port 3000 --pidfilepath $(pwd)/pid.file --logpath $(pwd)/logpath
80+
MONGOCRYPTD_URI='mongodb://localhost:3000'
8081

8182
BASE_TAG=$LINUX_ARCH-alpine-base-node-$NODE_VERSION
8283
docker --debug buildx build --load --progress=plain \
@@ -87,5 +88,10 @@ docker --debug buildx build --load --progress=plain \
8788
-f ./.evergreen/docker/Dockerfile.musl -t test-tag-1 \
8889
.
8990

90-
docker --debug run --platform linux/$LINUX_ARCH -e MONGODB_URI=${MONGODB_URI} --network host --entrypoint bash test-tag-1 '.evergreen/run-alpine-fle-tests.sh'
91-
# docker --debug run --network host --platform linux/$LINUX_ARCH -e MONGODB_URI=$MONGODB_URI --entrypoint bash -ti test-tag-1
91+
docker --debug run \
92+
--platform linux/$LINUX_ARCH \
93+
-e MONGODB_URI=${MONGODB_URI} -e MONGOCRYPTD_URI=${MONGOCRYPTD_URI} \
94+
--network host \
95+
--entrypoint bash \
96+
test-tag-1 \
97+
'.evergreen/run-alpine-fle-tests.sh'

start-cluster.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as path from 'path';
66
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
77
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
88
import { type CommandStartedEvent, MongoClient, type MongoClientOptions } from '../../mongodb';
9-
import { getEncryptExtraOptions } from '../../tools/utils';
109
import { dropCollection } from '../shared';
10+
import { TestConfiguration } from '../../tools/runner/config';
1111

1212
/* REFERENCE: (note commit hash) */
1313
/* https://github.com/mongodb/specifications/blob/b3beada 72ae1c992294ae6a8eea572003a274c35/source/client-side-encryption/tests/README.rst#deadlock-tests */
@@ -30,20 +30,24 @@ const $jsonSchema = BSON.EJSON.parse(
3030
)
3131
);
3232

33-
class CapturingMongoClient extends MongoClient {
34-
commandStartedEvents: Array<CommandStartedEvent> = [];
35-
clientsCreated = 0;
36-
constructor(url: string, options: MongoClientOptions = {}) {
37-
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
38-
if (process.env.MONGODB_API_VERSION) {
39-
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
40-
}
33+
function makeClient(configuration: TestConfiguration, options: MongoClientOptions = {}): MongoClient &
34+
{
35+
commandStartedEvents: Array<CommandStartedEvent>,
36+
clientsCreated: number
37+
} {
38+
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
39+
if (process.env.MONGODB_API_VERSION) {
40+
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
41+
}
4142

42-
super(url, options);
43+
const client = configuration.newClient(undefined, options) as ReturnType<typeof makeClient>;
4344

44-
this.on('commandStarted', ev => this.commandStartedEvents.push(ev));
45-
this.on('topologyOpening', () => this.clientsCreated++);
46-
}
45+
client.commandStartedEvents = [];
46+
client.clientsCreated = 0;
47+
client.on('commandStarted', ev => client.commandStartedEvents.push(ev));
48+
client.on('topologyOpening', () => client.clientsCreated++);
49+
50+
return client;
4751
}
4852

4953
function deadlockTest(
@@ -55,7 +59,6 @@ function deadlockTest(
5559
assertions
5660
) {
5761
return async function () {
58-
const url = this.configuration.url();
5962
const clientTest = this.clientTest;
6063
const ciphertext = this.ciphertext;
6164

@@ -64,17 +67,12 @@ function deadlockTest(
6467
keyVaultNamespace: 'keyvault.datakeys',
6568
kmsProviders: { local: { key: LOCAL_KEY } },
6669
bypassAutoEncryption,
67-
keyVaultClient: useKeyVaultClient ? this.clientKeyVault : undefined,
68-
extraOptions: {
69-
// ...getEncryptExtraOptions(),
70-
mongocryptdBypassSpawn: true,
71-
mongocryptdURI: 'mongodb://localhost:3000'
72-
}
70+
keyVaultClient: useKeyVaultClient ? this.clientKeyVault : undefined
7371
},
7472
maxPoolSize
7573
};
7674

77-
const clientEncrypted = new CapturingMongoClient(url, clientEncryptedOpts);
75+
const clientEncrypted = makeClient(this.configuration, clientEncryptedOpts);
7876

7977
await clientEncrypted.connect();
8078

@@ -99,30 +97,19 @@ function deadlockTest(
9997
};
10098
}
10199

102-
const metadata = {
100+
const metadata: MongoDBMetadataUI = {
103101
requires: {
104102
clientSideEncryption: true,
105103
mongodb: '>=4.2.0',
106104
topology: '!load-balanced'
107105
}
108106
};
109-
describe('Connection Pool Deadlock Prevention', function () {
107+
describe.only('Connection Pool Deadlock Prevention', function () {
110108
beforeEach(async function () {
111-
const url: string = this.configuration.url();
112-
113-
const options = process.env.ALPINE ? {
114-
autoEncryption: {
115-
extraOptions: {
116-
mongocryptdBypassSpawn: true,
117-
mongocryptdURI: 'mongodb://localhost:3000'
118-
}
119-
}
120-
} : {};
121-
this.clientTest = new CapturingMongoClient(url, options);
122-
this.clientKeyVault = new CapturingMongoClient(url, {
109+
this.clientTest = makeClient(this.configuration);
110+
this.clientKeyVault = makeClient(this.configuration, {
123111
monitorCommands: true,
124112
maxPoolSize: 1,
125-
...options
126113
});
127114

128115
this.clientEncryption = undefined;
@@ -155,7 +142,7 @@ describe('Connection Pool Deadlock Prevention', function () {
155142
});
156143

157144
afterEach(function () {
158-
return Promise.all([this.clientKeyVault.close(), this.clientTest.close()]).then(() => {
145+
return Promise.all([this.clientKeyVault?.close(), this.clientTest?.close()]).then(() => {
159146
this.clientKeyVault = undefined;
160147
this.clientTest = undefined;
161148
this.clientEncryption = undefined;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
ClientSideEncryptionFilter
2121
} = require('../../tools/runner/filters/client_encryption_filter');
2222
const { getCSFLEKMSProviders } = require('../../csfle-kms-providers');
23+
const { AlpineTestConfiguration } = require('../../tools/runner/config');
2324

2425
const getKmsProviders = (localKey, kmipEndpoint, azureEndpoint, gcpEndpoint) => {
2526
const result = getCSFLEKMSProviders();
@@ -1113,7 +1114,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
11131114
// configure with `client_encrypted` to use the schema `external/external-schema.json` for
11141115
// `db.coll` by setting a schema map like `{"db.coll": <contents of external-schema.json }`
11151116
beforeEach(async function () {
1116-
if (process.env.ALPINE) {
1117+
if (this.configuration instanceof AlpineTestConfiguration) {
11171118
this.currentTest.skipReason =
11181119
'alpine tests cannot spawn mongocryptds or use the crypt_shared.';
11191120
this.skip();

test/tools/runner/config.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,6 @@ export class TestConfiguration {
287287
delete urlOptions.query?.auth;
288288
}
289289

290-
if (serverOptions.autoEncryption) {
291-
serverOptions.autoEncryption.extraOptions = {
292-
mongocryptdBypassSpawn: true,
293-
mongocryptdURI: 'mongodb://localhost:3000'
294-
}
295-
}
296-
297290
const connectionString = url.format(urlOptions);
298291

299292
return new MongoClient(connectionString, serverOptions);
@@ -467,3 +460,21 @@ export class AstrolabeTestConfiguration extends TestConfiguration {
467460
return process.env.DRIVERS_ATLAS_TESTING_URI!;
468461
}
469462
}
463+
464+
export class AlpineTestConfiguration extends TestConfiguration {
465+
override newClient(urlOrQueryOptions?: string | Record<string, any>, serverOptions?: MongoClientOptions): MongoClient {
466+
const options = serverOptions ?? {};
467+
468+
if (options.autoEncryption) {
469+
const extraOptions: MongoClientOptions['autoEncryption']['extraOptions'] = {
470+
...options.autoEncryption.extraOptions,
471+
mongocryptdBypassSpawn: true,
472+
mongocryptdURI: 'mongodb://localhost:3000'
473+
// mongocryptdURI: process.env.MONGOCRYPTD_URI
474+
}
475+
options.autoEncryption.extraOptions = extraOptions;
476+
}
477+
478+
return super.newClient(urlOrQueryOptions, options);
479+
}
480+
}

test/tools/runner/hooks/configuration.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('source-map-support').install({
66
});
77

88
import { MongoClient } from '../../../mongodb';
9-
import { AstrolabeTestConfiguration, TestConfiguration } from '../config';
9+
import { AlpineTestConfiguration, AstrolabeTestConfiguration, TestConfiguration } from '../config';
1010
import { getEnvironmentalOptions } from '../../utils';
1111
import * as mock from '../../mongodb-mock/index';
1212
import { inspect } from 'util';
@@ -153,7 +153,8 @@ const testConfigBeforeHook = async function () {
153153
.command({ getParameter: '*' })
154154
.catch(error => ({ noReply: error }));
155155

156-
this.configuration = new TestConfiguration(
156+
const Config: typeof TestConfiguration = process.env.ALPINE ? AlpineTestConfiguration : TestConfiguration;
157+
this.configuration = new Config(
157158
loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI,
158159
context
159160
);
@@ -169,6 +170,8 @@ const testConfigBeforeHook = async function () {
169170
version: this.configuration.buildInfo.version,
170171
node: process.version,
171172
os: process.platform,
173+
alpineLinux: Boolean(process.env.ALPINE),
174+
cryptdUri: process.env.MONGOCRYPTD_URI,
172175
pid: process.pid,
173176
serverless: process.env.SERVERLESS === '1',
174177
auth: process.env.AUTH === 'auth',
@@ -186,7 +189,7 @@ const testConfigBeforeHook = async function () {
186189
adl: this.configuration.buildInfo.dataLake
187190
? this.configuration.buildInfo.dataLake.version
188191
: false,
189-
kerberos: process.env.KRB5_PRINCIPAL != null,
192+
kerberos: process.env.PRINCIPAL != null,
190193
ldap: MONGODB_URI.includes('authMechanism=PLAIN'),
191194
socks5: MONGODB_URI.includes('proxyHost='),
192195
compressor: process.env.COMPRESSOR,

0 commit comments

Comments
 (0)