Skip to content

Commit d21fe68

Browse files
fracasulanodkz
authored andcommitted
feat(ReplicaSet): set electionTimeoutMillis to 500ms instead of 10s as default value
* electionTimeoutMillis default to 500ms * All defaults in constructor * Changed default to avoid accidental overriding * Changed default to avoid accidental overriding
1 parent c8f115b commit d21fe68

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

README.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,6 @@ const replSet = new MongoMemoryReplSet({
158158
});
159159
```
160160
161-
The `replSet.configSettings` can be used to tune the initialization of the replica set. By default one of the nodes has
162-
to be promoted to Primary before the replica set can be successfully used but that happens only after a timeout of 10 seconds
163-
(see [electionTimeoutMillis](https://docs.mongodb.com/manual/reference/replica-configuration/#rsconf.settings.electionTimeoutMillis)).
164-
165-
It is possible to force the replica set to elect a node as Primary before the default 10 seconds by changing the `electionTimeoutMillis`
166-
parameter as shown below:
167-
168-
```js
169-
const replSet = new MongoMemoryReplSet({
170-
replSet: {
171-
configSettings: {
172-
electionTimeoutMillis: 100,
173-
},
174-
},
175-
});
176-
await replSet.waitUntilRunning();
177-
```
178-
179161
### Simple test with MongoClient
180162
181163
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.ts).

src/MongoMemoryReplSet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ export default class MongoMemoryReplSet extends EventEmitter {
224224
const rsConfig = {
225225
_id: this.opts.replSet.name,
226226
members,
227-
settings: this.opts.replSet.configSettings || {},
227+
settings: {
228+
electionTimeoutMillis: 500,
229+
...(this.opts.replSet.configSettings || {}),
230+
},
228231
};
229232
await this.admin.command({ replSetInitiate: rsConfig });
230233
this.debug('Waiting for replica set to have a PRIMARY member.');

0 commit comments

Comments
 (0)