Skip to content

Commit 985cb9e

Browse files
committed
test: breaking changes
1 parent e636d1e commit 985cb9e

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

test/functional/connection.test.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { withClient, setupDatabase } = require('./shared');
33
const test = require('./shared').assert;
44
const { expect } = require('chai');
55
const { ServerHeartbeatStartedEvent } = require('../../src');
6+
const { Topology } = require('../../src/sdam/topology');
67

78
describe('Connection - functional', function () {
89
before(function () {
@@ -70,21 +71,16 @@ describe('Connection - functional', function () {
7071
}
7172
});
7273

73-
it('should correctly connect to server using just events', {
74-
metadata: {
75-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
76-
},
77-
78-
test: function (done) {
79-
var configuration = this.configuration;
80-
var client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
74+
it('should correctly connect to server using just events', function (done) {
75+
var configuration = this.configuration;
76+
var client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
8177

82-
client.on('open', function () {
83-
client.close(done);
84-
});
78+
client.on('open', topology => {
79+
expect(topology).to.be.instanceOf(Topology);
80+
client.close(done);
81+
});
8582

86-
client.connect();
87-
}
83+
client.connect();
8884
});
8985

9086
it('should correctly connect to server using big connection pool', {

test/unit/sdam/srv_polling.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,35 @@ describe('Mongos SRV Polling', function () {
425425
});
426426
});
427427
});
428+
429+
it('should emit a topologyDescriptionChanged event upon receiving an SRV update', function () {
430+
const topology = new Topology(['localhost:27017'], { srvHost: SRV_HOST });
431+
432+
return new Promise(resolve => {
433+
topology.on(Topology.TOPOLOGY_DESCRIPTION_CHANGED, ev => {
434+
if (ev.topologyId === 'fake') {
435+
// the fake description change emitted within this test
436+
expect(topology.s.handleSrvPolling).to.be.a('function');
437+
expect(ev.newDescription.servers.size).to.equal(0);
438+
topology.s.handleSrvPolling(
439+
new SrvPollingEvent([srvRecord('localhost', 27017), srvRecord('localhost', 27018)])
440+
);
441+
} else {
442+
// topologyDescriptionChanged event emitted from the handleSrvPolling function
443+
expect(ev.topologyId).to.equal(1);
444+
expect(ev.newDescription.servers.size).to.equal(2);
445+
resolve();
446+
}
447+
});
448+
449+
topology.emit(
450+
Topology.TOPOLOGY_DESCRIPTION_CHANGED,
451+
new sdamEvents.TopologyDescriptionChangedEvent(
452+
'fake',
453+
new TopologyDescription(TopologyType.Unknown),
454+
new TopologyDescription(TopologyType.Sharded)
455+
)
456+
);
457+
});
458+
});
428459
});

0 commit comments

Comments
 (0)