Skip to content

Commit d097929

Browse files
authored
ci: Fix invalid MongoDB version ranges for tests (#9474)
1 parent 6146777 commit d097929

File tree

6 files changed

+64
-60
lines changed

6 files changed

+64
-60
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ If your pull request introduces a change that may affect the storage or retrieva
263263
* If your feature is intended to work with MongoDB and PostgreSQL, you can include or exclude tests more granularly with:
264264

265265
- `it_only_mongodb_version('>=4.4')` // will test with any version of Postgres but only with version >=4.4 of MongoDB; accepts semver notation to specify a version range
266-
- `it_exclude_mongodb_version('<4.4')` // will test with any version of Postgres and MongoDB, excluding version <4.4 of MongoDB; accepts semver notation to specify a version range
267266
- `it_only_postgres_version('>=13')` // will test with any version of Mongo but only with version >=13 of Postgres; accepts semver notation to specify a version range
268-
- `it_exclude_postgres_version('<13')` // will test with any version of Postgres and MongoDB, excluding version <13 of Postgres; accepts semver notation to specify a version range
269267

270268
#### Postgres with Docker
271269

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"test:mongodb:5.3.2": "npm run test:mongodb --dbversion=5.3.2",
127127
"test:mongodb:6.0.2": "npm run test:mongodb --dbversion=6.0.2",
128128
"test:mongodb:7.0.1": "npm run test:mongodb --dbversion=7.0.1",
129+
"test:mongodb:8.0.3": "npm run test:mongodb --dbversion=8.0.3",
129130
"test:postgres:testonly": "cross-env PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly",
130131
"pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=5.3.2} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} mongodb-runner start -t ${MONGODB_TOPOLOGY} --version ${MONGODB_VERSION} -- --port 27017",
131132
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=5.3.2} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} TESTING=1 jasmine",

spec/.eslintrc.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
"it_only_postgres_version": true,
2323
"it_only_node_version": true,
2424
"fit_only_mongodb_version": true,
25+
"fit_only_postgres_version": true,
2526
"fit_only_node_version": true,
26-
"it_exclude_mongodb_version": true,
27-
"it_exclude_postgres_version": true,
28-
"fit_exclude_mongodb_version": true,
29-
"fit_exclude_node_version": true,
3027
"it_exclude_dbs": true,
3128
"fit_exclude_dbs": true,
3229
"describe_only_db": true,

spec/MongoStorageAdapter.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
390390
await expectAsync(adapter.getClass('UnknownClass')).toBeRejectedWith(undefined);
391391
});
392392

393-
it_only_mongodb_version('<5.1>=6')('should use index for caseInsensitive query', async () => {
393+
it_only_mongodb_version('<5.1 || >=6')('should use index for caseInsensitive query', async () => {
394394
const user = new Parse.User();
395395
user.set('username', 'Bugs');
396396
user.set('password', 'Bunny');
@@ -424,7 +424,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
424424
expect(postIndexPlan.executionStats.executionStages.stage).toBe('FETCH');
425425
});
426426

427-
it_only_mongodb_version('>=5.1<6')('should use index for caseInsensitive query', async () => {
427+
it_only_mongodb_version('>=5.1 <6')('should use index for caseInsensitive query', async () => {
428428
const user = new Parse.User();
429429
user.set('username', 'Bugs');
430430
user.set('password', 'Bunny');

spec/ParseQuery.hint.spec.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
2727
await TestUtils.destroyAllDataPermanently(false);
2828
});
2929

30-
it_only_mongodb_version('<5.1>=6')('query find with hint string', async () => {
30+
it_only_mongodb_version('<5.1 || >=6 <8')('query find with hint string', async () => {
3131
const object = new TestObject();
3232
await object.save();
3333

@@ -39,7 +39,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
3939
expect(explain.queryPlanner.winningPlan.inputStage.indexName).toBe('_id_');
4040
});
4141

42-
it_only_mongodb_version('>=5.1<6')('query find with hint string', async () => {
42+
it_only_mongodb_version('>=5.1 <6')('query find with hint string', async () => {
4343
const object = new TestObject();
4444
await object.save();
4545

@@ -50,7 +50,19 @@ describe_only_db('mongo')('Parse.Query hint', () => {
5050
expect(explain.queryPlanner.winningPlan.queryPlan.inputStage.indexName).toBe('_id_');
5151
});
5252

53-
it_only_mongodb_version('<5.1>=6')('query find with hint object', async () => {
53+
it_only_mongodb_version('>=8')('query find with hint string', async () => {
54+
const object = new TestObject();
55+
await object.save();
56+
57+
const collection = await config.database.adapter._adaptiveCollection('TestObject');
58+
let explain = await collection._rawFind({ _id: object.id }, { explain: true });
59+
expect(explain.queryPlanner.winningPlan.stage).toBe('EXPRESS_IXSCAN');
60+
explain = await collection._rawFind({ _id: object.id }, { hint: '_id_', explain: true });
61+
expect(explain.queryPlanner.winningPlan.stage).toBe('FETCH');
62+
expect(explain.queryPlanner.winningPlan.inputStage.indexName).toBe('_id_');
63+
});
64+
65+
it_only_mongodb_version('<5.1 || >=6 <8')('query find with hint object', async () => {
5466
const object = new TestObject();
5567
await object.save();
5668

@@ -64,7 +76,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
6476
});
6577
});
6678

67-
it_only_mongodb_version('>=5.1<6')('query find with hint object', async () => {
79+
it_only_mongodb_version('>=5.1 <6')('query find with hint object', async () => {
6880
const object = new TestObject();
6981
await object.save();
7082

@@ -78,6 +90,20 @@ describe_only_db('mongo')('Parse.Query hint', () => {
7890
expect(explain.queryPlanner.winningPlan.queryPlan.inputStage.keyPattern).toEqual({ _id: 1 });
7991
});
8092

93+
it_only_mongodb_version('>=8')('query find with hint object', async () => {
94+
const object = new TestObject();
95+
await object.save();
96+
97+
const collection = await config.database.adapter._adaptiveCollection('TestObject');
98+
let explain = await collection._rawFind({ _id: object.id }, { explain: true });
99+
expect(explain.queryPlanner.winningPlan.stage).toBe('EXPRESS_IXSCAN');
100+
explain = await collection._rawFind({ _id: object.id }, { hint: { _id: 1 }, explain: true });
101+
expect(explain.queryPlanner.winningPlan.stage).toBe('FETCH');
102+
expect(explain.queryPlanner.winningPlan.inputStage.keyPattern).toEqual({
103+
_id: 1,
104+
});
105+
});
106+
81107
it_only_mongodb_version('<4.4')('query aggregate with hint string', async () => {
82108
const object = new TestObject({ foo: 'bar' });
83109
await object.save();
@@ -100,7 +126,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
100126
expect(queryPlanner.winningPlan.inputStage.indexName).toBe('_id_');
101127
});
102128

103-
it_only_mongodb_version('>=4.4<5.1')('query aggregate with hint string', async () => {
129+
it_only_mongodb_version('>=4.4 <5.1')('query aggregate with hint string', async () => {
104130
const object = new TestObject({ foo: 'bar' });
105131
await object.save();
106132

@@ -124,7 +150,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
124150
expect(queryPlanner.winningPlan.inputStage.inputStage.indexName).toBe('_id_');
125151
});
126152

127-
it_only_mongodb_version('>=5.1<5.2')('query aggregate with hint string', async () => {
153+
it_only_mongodb_version('>=5.1 <5.2')('query aggregate with hint string', async () => {
128154
const object = new TestObject({ foo: 'bar' });
129155
await object.save();
130156

@@ -192,7 +218,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
192218
expect(queryPlanner.winningPlan.inputStage.keyPattern).toEqual({ _id: 1 });
193219
});
194220

195-
it_only_mongodb_version('>=4.4<5.1')('query aggregate with hint object', async () => {
221+
it_only_mongodb_version('>=4.4 <5.1')('query aggregate with hint object', async () => {
196222
const object = new TestObject({ foo: 'bar' });
197223
await object.save();
198224

@@ -217,7 +243,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
217243
expect(queryPlanner.winningPlan.inputStage.inputStage.keyPattern).toEqual({ _id: 1 });
218244
});
219245

220-
it_only_mongodb_version('>=5.1<5.2')('query aggregate with hint object', async () => {
246+
it_only_mongodb_version('>=5.1 <5.2')('query aggregate with hint object', async () => {
221247
const object = new TestObject({ foo: 'bar' });
222248
await object.save();
223249

@@ -267,7 +293,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
267293
expect(queryPlanner.winningPlan.queryPlan.inputStage.inputStage.keyPattern).toEqual({ _id: 1 });
268294
});
269295

270-
it_only_mongodb_version('<5.1>=6')('query find with hint (rest)', async () => {
296+
it_only_mongodb_version('<5.1 || >=6')('query find with hint (rest)', async () => {
271297
const object = new TestObject();
272298
await object.save();
273299
let options = Object.assign({}, masterKeyOptions, {
@@ -292,7 +318,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
292318
expect(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName).toBe('_id_');
293319
});
294320

295-
it_only_mongodb_version('>=5.1<6')('query find with hint (rest)', async () => {
321+
it_only_mongodb_version('>=5.1 <6')('query find with hint (rest)', async () => {
296322
const object = new TestObject();
297323
await object.save();
298324
let options = Object.assign({}, masterKeyOptions, {
@@ -344,7 +370,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
344370
expect(queryPlanner.winningPlan.inputStage.keyPattern).toEqual({ _id: 1 });
345371
});
346372

347-
it_only_mongodb_version('>=4.4<5.1')('query aggregate with hint (rest)', async () => {
373+
it_only_mongodb_version('>=4.4 <5.1')('query aggregate with hint (rest)', async () => {
348374
const object = new TestObject({ foo: 'bar' });
349375
await object.save();
350376
let options = Object.assign({}, masterKeyOptions, {
@@ -377,7 +403,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
377403
expect(queryPlanner.winningPlan.inputStage.inputStage.keyPattern).toEqual({ _id: 1 });
378404
});
379405

380-
it_only_mongodb_version('>=5.1<5.2')('query aggregate with hint (rest)', async () => {
406+
it_only_mongodb_version('>=5.1 <5.2')('query aggregate with hint (rest)', async () => {
381407
const object = new TestObject({ foo: 'bar' });
382408
await object.save();
383409
let options = Object.assign({}, masterKeyOptions, {

spec/helper.js

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ global.it_only_db = db => {
493493
};
494494

495495
global.it_only_mongodb_version = version => {
496+
if (!semver.validRange(version)) {
497+
throw new Error('Invalid version range');
498+
}
496499
const envVersion = process.env.MONGODB_VERSION;
497500
if (!envVersion || semver.satisfies(envVersion, version)) {
498501
return it;
@@ -502,6 +505,9 @@ global.it_only_mongodb_version = version => {
502505
};
503506

504507
global.it_only_postgres_version = version => {
508+
if (!semver.validRange(version)) {
509+
throw new Error('Invalid version range');
510+
}
505511
const envVersion = process.env.POSTGRES_VERSION;
506512
if (!envVersion || semver.satisfies(envVersion, version)) {
507513
return it;
@@ -511,6 +517,9 @@ global.it_only_postgres_version = version => {
511517
};
512518

513519
global.it_only_node_version = version => {
520+
if (!semver.validRange(version)) {
521+
throw new Error('Invalid version range');
522+
}
514523
const envVersion = process.version;
515524
if (!envVersion || semver.satisfies(envVersion, version)) {
516525
return it;
@@ -520,62 +529,35 @@ global.it_only_node_version = version => {
520529
};
521530

522531
global.fit_only_mongodb_version = version => {
523-
const envVersion = process.env.MONGODB_VERSION;
524-
if (!envVersion || semver.satisfies(envVersion, version)) {
525-
return fit;
526-
} else {
527-
return xit;
532+
if (!semver.validRange(version)) {
533+
throw new Error('Invalid version range');
528534
}
529-
};
530-
531-
global.fit_only_node_version = version => {
532-
const envVersion = process.version;
535+
const envVersion = process.env.MONGODB_VERSION;
533536
if (!envVersion || semver.satisfies(envVersion, version)) {
534537
return fit;
535538
} else {
536539
return xit;
537540
}
538541
};
539542

540-
global.it_exclude_mongodb_version = version => {
541-
const envVersion = process.env.MONGODB_VERSION;
542-
if (!envVersion || !semver.satisfies(envVersion, version)) {
543-
return it;
544-
} else {
545-
return xit;
543+
global.fit_only_postgres_version = version => {
544+
if (!semver.validRange(version)) {
545+
throw new Error('Invalid version range');
546546
}
547-
};
548-
549-
global.it_exclude_postgres_version = version => {
550547
const envVersion = process.env.POSTGRES_VERSION;
551-
if (!envVersion || !semver.satisfies(envVersion, version)) {
552-
return it;
553-
} else {
554-
return xit;
555-
}
556-
};
557-
558-
global.it_exclude_node_version = version => {
559-
const envVersion = process.env.NODE_VERSION;
560-
if (!envVersion || !semver.satisfies(envVersion, version)) {
561-
return it;
562-
} else {
563-
return xit;
564-
}
565-
};
566-
567-
global.fit_exclude_mongodb_version = version => {
568-
const envVersion = process.env.MONGODB_VERSION;
569-
if (!envVersion || !semver.satisfies(envVersion, version)) {
548+
if (!envVersion || semver.satisfies(envVersion, version)) {
570549
return fit;
571550
} else {
572551
return xit;
573552
}
574553
};
575554

576-
global.fit_exclude_node_version = version => {
577-
const envVersion = process.env.NODE_VERSION;
578-
if (!envVersion || !semver.satisfies(envVersion, version)) {
555+
global.fit_only_node_version = version => {
556+
if (!semver.validRange(version)) {
557+
throw new Error('Invalid version range');
558+
}
559+
const envVersion = process.version;
560+
if (!envVersion || semver.satisfies(envVersion, version)) {
579561
return fit;
580562
} else {
581563
return xit;

0 commit comments

Comments
 (0)