Skip to content

Commit 5f42896

Browse files
fix compression tests
1 parent 99c217b commit 5f42896

File tree

2 files changed

+78
-16
lines changed

2 files changed

+78
-16
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { expect } from 'chai';
2+
3+
describe('compression configuration tests', function () {
4+
describe('process.env.COMPRESSOR is set', function () {
5+
it(
6+
'enables compression when set in the environment',
7+
{
8+
requires: {
9+
predicate: () => !!process.env.COMPRESSOR || 'compression must be enabled.'
10+
}
11+
},
12+
function () {
13+
const client = this.configuration.newClient();
14+
expect(client.s.options.compressors).to.deep.equal([process.env.COMPRESSOR]);
15+
}
16+
);
17+
18+
it(
19+
'enables compression when set in the environment',
20+
{
21+
requires: {
22+
predicate: () => !!process.env.COMPRESSOR || 'compression must be enabled.'
23+
}
24+
},
25+
function () {
26+
const url = this.configuration.url();
27+
expect(url).to.include(`compressors=${process.env.COMPRESSOR}`);
28+
}
29+
);
30+
});
31+
32+
describe('process.env.COMPRESSOR is unset', function () {
33+
it(
34+
'enables compression when set in the environment',
35+
{
36+
requires: {
37+
predicate: () => !process.env.COMPRESSOR || 'compression cannot be enabled.'
38+
}
39+
},
40+
function () {
41+
const client = this.configuration.newClient();
42+
43+
expect(client.s.options.compressors).to.deep.equal(['none']);
44+
}
45+
);
46+
47+
it(
48+
'enables compression when set in the environment',
49+
{
50+
requires: {
51+
predicate: () => !process.env.COMPRESSOR || 'compression cannot be enabled.'
52+
}
53+
},
54+
function () {
55+
const url = this.configuration.url();
56+
expect(url).to.not.include(`compressors=none`);
57+
}
58+
);
59+
});
60+
});

test/tools/runner/config.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ function convertToConnStringMap(obj: Record<string, any>) {
6565
return result.join(',');
6666
}
6767

68-
function getCompressor(compressor: string): CompressorName {
68+
function getCompressor(compressor: string | undefined): CompressorName {
69+
if (!compressor) return null;
70+
6971
switch (compressor) {
7072
case 'zstd':
7173
return 'zstd';
@@ -74,7 +76,7 @@ function getCompressor(compressor: string): CompressorName {
7476
case 'snappy':
7577
return 'snappy';
7678
default:
77-
return 'none';
79+
throw new Error('unsupported test runner compressor, would default to no compression');
7880
}
7981
}
8082

@@ -137,11 +139,11 @@ export class TestConfiguration {
137139
replicaSet: url.searchParams.get('replicaSet'),
138140
proxyURIParams: url.searchParams.get('proxyHost')
139141
? {
140-
proxyHost: url.searchParams.get('proxyHost'),
141-
proxyPort: Number(url.searchParams.get('proxyPort')),
142-
proxyUsername: url.searchParams.get('proxyUsername'),
143-
proxyPassword: url.searchParams.get('proxyPassword')
144-
}
142+
proxyHost: url.searchParams.get('proxyHost'),
143+
proxyPort: Number(url.searchParams.get('proxyPort')),
144+
proxyUsername: url.searchParams.get('proxyUsername'),
145+
proxyPassword: url.searchParams.get('proxyPassword')
146+
}
145147
: undefined
146148
};
147149
if (url.username) {
@@ -216,13 +218,13 @@ export class TestConfiguration {
216218
}
217219

218220
newClient(urlOrQueryOptions?: string | Record<string, any>, serverOptions?: MongoClientOptions) {
219-
serverOptions = Object.assign(
220-
<MongoClientOptions>{
221-
compressors: this.compressor
222-
},
223-
getEnvironmentalOptions(),
224-
serverOptions
225-
);
221+
const baseOptions: MongoClientOptions = this.compressor
222+
? {
223+
compressors: this.compressor
224+
}
225+
: {};
226+
227+
serverOptions = Object.assign(baseOptions, getEnvironmentalOptions(), serverOptions);
226228

227229
if (this.loggingEnabled && !Object.hasOwn(serverOptions, 'mongodbLogPath')) {
228230
serverOptions = this.setupLogging(serverOptions);
@@ -336,14 +338,12 @@ export class TestConfiguration {
336338
authSource?: string;
337339
authMechanism?: string;
338340
authMechanismProperties?: Record<string, any>;
339-
compressors?: CompressorName;
340341
}
341342
) {
342343
options = {
343344
db: this.options.db,
344345
replicaSet: this.options.replicaSet,
345346
proxyURIParams: this.options.proxyURIParams,
346-
compressors: this.compressor,
347347
...options
348348
};
349349

@@ -423,6 +423,8 @@ export class TestConfiguration {
423423
url.searchParams.append('authSource', 'admin');
424424
}
425425

426+
this.compressor && url.searchParams.append('compressors', this.compressor);
427+
426428
// Secrets setup for OIDC always sets the workload URI as MONGODB_URI_SINGLE.
427429
if (process.env.MONGODB_URI_SINGLE?.includes('MONGODB-OIDC')) {
428430
return process.env.MONGODB_URI_SINGLE;

0 commit comments

Comments
 (0)