Skip to content

Commit 104582d

Browse files
committed
test: fix unit test
1 parent fa34de2 commit 104582d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/unit/cmap/connect.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,28 @@ describe('Connect Tests', function () {
159159
server.setMessageHandler(() => null);
160160

161161
const cancellationToken = new CancellationToken();
162-
setTimeout(() => cancellationToken.emit('cancel'), 500);
162+
// Make sure the cancel listener is added before emitting cancel
163+
cancellationToken.addListener('newListener', () => {
164+
process.nextTick(() => {
165+
cancellationToken.emit('cancel');
166+
});
167+
});
163168

164169
const error = await promisify<Connection>(callback =>
165170
connect(
166171
{
167172
...connectOptions,
168173
// Ensure these timeouts do not fire first
169-
socketTimeoutMS: 1000,
170-
connectTimeoutMS: 1000,
174+
socketTimeoutMS: 5000,
175+
connectTimeoutMS: 5000,
171176
cancellationToken
172177
},
173178
//@ts-expect-error: Callbacks do not have mutual exclusion for error/result existence
174179
callback
175180
)
176181
)().catch(error => error);
177182

178-
expect(error).to.match(/connection establishment was cancelled/);
183+
expect(error, error.stack).to.match(/connection establishment was cancelled/);
179184
});
180185
});
181186

0 commit comments

Comments
 (0)