Skip to content

Commit 63a3a6e

Browse files
committed
test: fix cancellationToken test
1 parent 910dfaf commit 63a3a6e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

test/unit/cmap/connect.test.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ describe('Connect Tests', function () {
152152
it('connection instance has property socketTimeoutMS equal to the value passed in the connectOptions', async () => {
153153
expect(connection).to.have.property('socketTimeoutMS', 15000);
154154
});
155+
156+
it('cancels connecting if provided cancellationToken emits cancel', async () => {
157+
// set no response handler for mock server, effectively black hole requests
158+
server.setMessageHandler(() => null);
159+
160+
const cancellationToken = new CancellationToken();
161+
setTimeout(() => cancellationToken.emit('cancel'), 5);
162+
163+
const error = await promisify<Connection>(callback =>
164+
//@ts-expect-error: Callbacks do not have mutual exclusion for error/result existence
165+
connect({ ...connectOptions, cancellationToken }, callback)
166+
)().catch(error => error);
167+
168+
expect(error).to.match(/connection establishment was cancelled/);
169+
});
155170
});
156171

157172
it('should emit `MongoNetworkError` for network errors', function (done) {
@@ -161,19 +176,6 @@ describe('Connect Tests', function () {
161176
});
162177
});
163178

164-
it.skip('should allow a cancellaton token', function (done) {
165-
const cancellationToken = new CancellationToken();
166-
setTimeout(() => cancellationToken.emit('cancel'), 500);
167-
// set no response handler for mock server, effectively black hole requests
168-
169-
connect({ hostAddress: new HostAddress('240.0.0.1'), cancellationToken }, (err, conn) => {
170-
expect(err).to.exist;
171-
expect(err).to.match(/connection establishment was cancelled/);
172-
expect(conn).to.not.exist;
173-
done();
174-
});
175-
}).skipReason = 'TODO(NODE-2941): stop using 240.0.0.1 in tests';
176-
177179
context('prepareHandshakeDocument', () => {
178180
const prepareHandshakeDocument = promisify(prepareHandshakeDocumentCb);
179181

0 commit comments

Comments
 (0)