Skip to content

Commit 7d4c88a

Browse files
committed
test: fix sessions tests on 3.6 sharded clusters
SERVER-37631 requires that 3.6 servers have a command run on them to report `logicalSessionsTimeoutMinutes` on connected proxies.
1 parent b972c1e commit 7d4c88a

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

test/config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class NativeConfiguration extends ConfigurationBase {
3535
console.log('[purge the directories]');
3636
return self.manager.start();
3737
})
38+
.then(() => {
39+
if (this.environment.server37631WorkaroundNeeded) {
40+
return this.server37631Workaround();
41+
}
42+
})
3843
.then(function() {
3944
console.log('[started the topology]');
4045
return client.connect();
@@ -118,6 +123,26 @@ class NativeConfiguration extends ConfigurationBase {
118123
writeConcernMax() {
119124
return Object.assign({}, this.options.writeConcernMax || { w: 1 });
120125
}
126+
127+
server37631Workaround() {
128+
console.log('[applying SERVER-37631 workaround]');
129+
const configServers = this.manager.configurationServers.managers;
130+
const proxies = this.manager.proxies;
131+
132+
const configServersPromise = configServers.reduce((result, server) => {
133+
return result.then(() =>
134+
server.executeCommand('admin.$cmd', { refreshLogicalSessionCacheNow: 1 })
135+
);
136+
}, Promise.resolve());
137+
138+
return configServersPromise.then(() => {
139+
return proxies.reduce((promise, proxy) => {
140+
return promise.then(() =>
141+
proxy.executeCommand('admin.$cmd', { refreshLogicalSessionCacheNow: 1 })
142+
);
143+
}, Promise.resolve());
144+
});
145+
}
121146
}
122147

123148
module.exports = NativeConfiguration;

test/environments.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ const genConfigNode = (port, options) => {
115115
options: {
116116
bind_ip: 'localhost',
117117
port: port,
118-
dbpath: `${__dirname}/../db/${port}`
118+
dbpath: `${__dirname}/../db/${port}`,
119+
setParameter: ['enableTestCommands=1']
119120
}
120121
},
121122
options
@@ -126,7 +127,7 @@ const genConfigNode = (port, options) => {
126127
*
127128
*/
128129
class ShardedEnvironment extends EnvironmentBase {
129-
constructor() {
130+
constructor(discoverResult) {
130131
super();
131132

132133
this.host = 'localhost';
@@ -140,6 +141,9 @@ class ShardedEnvironment extends EnvironmentBase {
140141
return new Mongos([new Server(host, port, options)], options);
141142
};
142143

144+
const version =
145+
discoverResult && discoverResult.version ? discoverResult.version.join('.') : null;
146+
this.server37631WorkaroundNeeded = semver.satisfies(version, '3.6.x');
143147
this.manager = new ShardingManager({
144148
mongod: 'mongod',
145149
mongos: 'mongos'
@@ -157,11 +161,7 @@ class ShardedEnvironment extends EnvironmentBase {
157161
];
158162

159163
const configOptions = this.options && this.options.config ? this.options.config : {};
160-
const configNodes = [
161-
genConfigNode(35000, configOptions),
162-
genConfigNode(35001, configOptions),
163-
genConfigNode(35002, configOptions)
164-
];
164+
const configNodes = [genConfigNode(35000, configOptions)];
165165

166166
let proxyNodes = [
167167
{

0 commit comments

Comments
 (0)