Skip to content

Commit f7d7d11

Browse files
fix: shuffle servers when only two servers are selected
1 parent 4f0b7f9 commit f7d7d11

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/sdam/topology.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,7 @@ function processWaitQueue(topology: Topology) {
904904
} else if (selectedDescriptions.length === 1) {
905905
selectedServer = topology.s.servers.get(selectedDescriptions[0].address);
906906
} else {
907-
// don't shuffle the array if there are only two elements
908-
const descriptions =
909-
selectedDescriptions.length === 2 ? selectedDescriptions : shuffle(selectedDescriptions, 2);
907+
const descriptions = shuffle(selectedDescriptions, 2);
910908
const server1 = topology.s.servers.get(descriptions[0].address);
911909
const server2 = topology.s.servers.get(descriptions[1].address);
912910

test/integration/server-selection/server_selection.prose.operation_count.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ describe('operationCount-based Selection Within Latency Window - Prose Test', fu
166166
expect(percentageToHost2).to.be.greaterThan(40).and.lessThan(60);
167167
});
168168

169-
it.only(
170-
'equally distributes operations with both hosts are fine test 2',
169+
it(
170+
'equally distributes operations with both hosts when requests are in parallel',
171171
TEST_METADATA,
172172
async function () {
173173
const collection = client.db('test-db').collection('collection0');
174174

175175
const { insertedId } = await collection.insertOne({ name: 'bumpy' });
176176

177-
const n = 2000;
177+
const n = 1000;
178178

179179
for (let i = 0; i < n; ++i) {
180180
await collection.findOne({ _id: insertedId });
@@ -184,7 +184,6 @@ describe('operationCount-based Selection Within Latency Window - Prose Test', fu
184184
const [host1, host2] = seeds.map(seed => seed.split(':')[1]);
185185
const percentageToHost1 = (counts[host1] / n) * 100;
186186
const percentageToHost2 = (counts[host2] / n) * 100;
187-
console.error({ percentageToHost1, percentageToHost2 });
188187
expect(percentageToHost1).to.be.greaterThan(40).and.lessThan(60);
189188
expect(percentageToHost2).to.be.greaterThan(40).and.lessThan(60);
190189
}

0 commit comments

Comments
 (0)