Skip to content

Commit 011ecce

Browse files
committed
chore: move fake server to utils
1 parent ede31fd commit 011ecce

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

test/tools/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,17 @@ export async function makeMultiResponseBatchModelArray(
463463
return models;
464464
}
465465

466+
export function fakeServer() {
467+
return {
468+
s: { state: 'connected' },
469+
removeListener: () => true,
470+
pool: {
471+
checkOut: async () => ({}),
472+
checkIn: () => undefined
473+
}
474+
};
475+
}
476+
466477
/**
467478
* A utility to measure the duration of an async function. This is intended to be used for CSOT
468479
* testing, where we expect to timeout within a certain threshold and want to measure the duration

test/unit/assorted/server_discovery_and_monitoring.spec.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { Server } from '../../../src/sdam/server';
3838
import { ServerDescription, type TopologyVersion } from '../../../src/sdam/server_description';
3939
import { Topology } from '../../../src/sdam/topology';
4040
import { isRecord, ns, squashError } from '../../../src/utils';
41-
import { ejson } from '../../tools/utils';
41+
import { ejson, fakeServer } from '../../tools/utils';
4242

4343
const SDAM_EVENT_CLASSES = {
4444
ServerDescriptionChangedEvent,
@@ -214,16 +214,7 @@ describe('Server Discovery and Monitoring (spec)', function () {
214214
.stub(Topology.prototype, 'selectServer')
215215
.callsFake(async function (_selector, _options) {
216216
topologySelectServers.restore();
217-
218-
const fakeServer = {
219-
s: { state: 'connected' },
220-
removeListener: () => true,
221-
pool: {
222-
checkOut: async () => ({}),
223-
checkIn: () => undefined
224-
}
225-
};
226-
return fakeServer;
217+
return fakeServer();
227218
});
228219
});
229220

test/unit/assorted/server_discovery_and_monitoring.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Server } from '../../../src/sdam/server';
88
import { ServerDescription } from '../../../src/sdam/server_description';
99
import { Topology } from '../../../src/sdam/topology';
1010
import { type TopologyDescription } from '../../../src/sdam/topology_description';
11+
import { fakeServer } from '../../tools/utils';
1112

1213
describe('Server Discovery and Monitoring', function () {
1314
let serverConnect: sinon.SinonStub;
@@ -30,16 +31,7 @@ describe('Server Discovery and Monitoring', function () {
3031
.stub(Topology.prototype, 'selectServer')
3132
.callsFake(async function (_selector, _options) {
3233
topologySelectServer.restore();
33-
34-
const fakeServer = {
35-
s: { state: 'connected' },
36-
removeListener: () => true,
37-
pool: {
38-
checkOut: async () => ({}),
39-
checkIn: () => undefined
40-
}
41-
};
42-
return fakeServer;
34+
return fakeServer();
4335
});
4436

4537
events = [];

test/unit/assorted/server_selection_spec_helper.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ServerSelectors = require('../../../src/sdam/server_selection');
99

1010
const sinon = require('sinon');
1111
const { expect } = require('chai');
12-
const { topologyWithPlaceholderClient } = require('../../tools/utils');
12+
const { fakeServer, topologyWithPlaceholderClient } = require('../../tools/utils');
1313

1414
export function serverDescriptionFromDefinition(definition, hosts) {
1515
hosts = hosts || [];
@@ -105,16 +105,7 @@ export async function executeServerSelectionTest(testDefinition) {
105105
.stub(Topology.prototype, 'selectServer')
106106
.callsFake(async function () {
107107
topologySelectServers.restore();
108-
109-
const fakeServer = {
110-
s: { state: 'connected' },
111-
removeListener: () => true,
112-
pool: {
113-
checkOut: async () => ({}),
114-
checkIn: () => undefined
115-
}
116-
};
117-
return fakeServer;
108+
return fakeServer();
118109
});
119110

120111
await topology.connect();

0 commit comments

Comments
 (0)