Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Sep 21, 2024
2 parents 6e68ddf + 8a989a3 commit d0968d8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [10.0.1-beta.1](https://github.com/typegoose/mongodb-memory-server/compare/v10.0.0...v10.0.1-beta.1) (2024-08-03)


### Fixes

* **getport:** check new port against cache ([b70d868](https://github.com/typegoose/mongodb-memory-server/commit/b70d868cf5b6766e751ef6fec53e8e4ccccd1de6)), closes [#883](https://github.com/typegoose/mongodb-memory-server/issues/883)
* **getport:** update cache time when last used ([a332b49](https://github.com/typegoose/mongodb-memory-server/commit/a332b491b173d9d3b03578c9f6bcd46fecbaa6d7)), closes [#883](https://github.com/typegoose/mongodb-memory-server/issues/883)

## [10.0.0](https://github.com/typegoose/mongodb-memory-server/compare/v9.4.1...v10.0.0) (2024-07-18)


Expand Down
2 changes: 1 addition & 1 deletion packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-core",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
"main": "lib/index",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ describe('MongoMemoryReplSet', () => {
describe('server version specific', () => {
// should use default options that are supported for 7.0 (like not using "ephemeralForTest" by default)
it('should allow mongodb by default 7.0', async () => {
const server = await MongoMemoryReplSet.create({ binary: { version: '7.0.7' } });
const server = await MongoMemoryReplSet.create({ binary: { version: '7.0.11' } });

await server.stop();
});
Expand All @@ -746,7 +746,7 @@ describe('MongoMemoryReplSet', () => {
it('should not warn if no explicit storage engine is set in 7.0', async () => {
jest.spyOn(console, 'warn');
const server = await MongoMemoryReplSet.create({
binary: { version: '7.0.7' },
binary: { version: '7.0.11' },
// replSet: { storageEngine: 'ephemeralForTest' },
});

Expand All @@ -760,7 +760,7 @@ describe('MongoMemoryReplSet', () => {
it('should warn if "ephemeralForTest" is used explicitly in mongodb 7.0', async () => {
const spy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
const server = await MongoMemoryReplSet.create({
binary: { version: '7.0.7' },
binary: { version: '7.0.11' },
replSet: { storageEngine: 'ephemeralForTest' },
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ describe('MongoMemoryServer', () => {
describe('server version specific', () => {
// should use default options that are supported for 7.0 (like not using "ephemeralForTest" by default)
it('should allow mongodb by default 7.0', async () => {
const server = await MongoMemoryServer.create({ binary: { version: '7.0.7' } });
const server = await MongoMemoryServer.create({ binary: { version: '7.0.11' } });

await server.stop();
});
Expand All @@ -1266,7 +1266,7 @@ describe('MongoMemoryServer', () => {
it('should not warn if no explicit storage engine is set in 7.0', async () => {
jest.spyOn(console, 'warn');
const server = await MongoMemoryServer.create({
binary: { version: '7.0.7' },
binary: { version: '7.0.11' },
// instance: { storageEngine: 'ephemeralForTest' },
});

Expand All @@ -1280,7 +1280,7 @@ describe('MongoMemoryServer', () => {
it('should warn if "ephemeralForTest" is used explicitly in mongodb 7.0', async () => {
const spy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
const server = await MongoMemoryServer.create({
binary: { version: '7.0.7' },
binary: { version: '7.0.11' },
instance: { storageEngine: 'ephemeralForTest' },
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('MongodbInstance', () => {
const mongod = await MongodbInstance.create({
// this works without problems, because no explicit storage-engine is given, so mongodb automatically chooses wiredTiger
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '7.0.0' },
binary: { version: '7.0.11' },
});
expect(mongod.mongodProcess!.pid).toBeGreaterThan(0);
await mongod.stop();
Expand Down
15 changes: 14 additions & 1 deletion packages/mongodb-memory-server-core/src/util/getport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,24 @@ export async function getFreePort(
const triedPort = await tryPort(nextPort);

if (triedPort > 0) {
log('getFreePort: found free port', triedPort);
// check if triedPort is already in the cache (ie the vm executed another instance's getport before binary startup)
// and that the triedPort is not a custom port
const inCacheAndNotSame = PORTS_CACHE.ports.has(triedPort) && nextPort !== triedPort;
log(
`getFreePort: found free port ${triedPort}, in cache and not custom: ${inCacheAndNotSame}`
);

// returned port can be different than the "nextPort" (if net0listen)
PORTS_CACHE.ports.add(nextPort);

// ensure that no other instance can get the same port if the vm decides to run the other instance's getport before starting the last one
if (inCacheAndNotSame) {
continue;
}

// reset the cache time as we now have just added new ports
PORTS_CACHE.timeSet = Date.now();

return triedPort;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.0",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"mongodb_version": "4.0.28",
"description": "MongoDB Server for testing (auto-download 4.0 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.0.0",
"mongodb-memory-server-core": "10.0.1-beta.1",
"tslib": "^2.6.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.2",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"mongodb_version": "4.2.24",
"description": "MongoDB Server for testing (auto-download 4.2 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.0.0",
"mongodb-memory-server-core": "10.0.1-beta.1",
"tslib": "^2.6.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.4",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"mongodb_version": "4.4.28",
"description": "MongoDB Server for testing (auto-download 4.4 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.0.0",
"mongodb-memory-server-core": "10.0.1-beta.1",
"tslib": "^2.6.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"description": "MongoDB Server for testing (auto-download latest version to ~/.cache/mongodb-binaries).",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -24,7 +24,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.0.0",
"mongodb-memory-server-core": "10.0.1-beta.1",
"tslib": "^2.6.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server",
"version": "10.0.0",
"version": "10.0.1-beta.1",
"description": "MongoDB Server for testing (auto-download latest version). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -24,7 +24,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.0.0",
"mongodb-memory-server-core": "10.0.1-beta.1",
"tslib": "^2.6.3"
},
"scripts": {
Expand Down

0 comments on commit d0968d8

Please sign in to comment.