You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/socket-mode/test/integration.spec.js
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -198,14 +198,22 @@ describe('Integration tests with a WebSocket server', () => {
198
198
client.on('close',()=>{
199
199
closed++;
200
200
});
201
+
202
+
letelapseTime=0;
203
+
letretries=0;
204
+
conststartTime=Date.now();
205
+
201
206
// do not use await here, since `start()` won't return until the connection is established. we are intentionally testing connection establishment failure, so that will never finish. so, let's run this in a rogue "thread", e.g. fire off an async method and let it do its thing!
202
207
client.start();
203
-
awaitsleep(50);
204
-
// after 50ms, with a timeout of 20ms, we would expect 2 retries.
208
+
do{
209
+
awaitsleep(2);
210
+
retries=closed;
211
+
elapseTime=Date.now()-startTime;
212
+
}while(retries<2&&elapseTime<50);
213
+
// after less then 50 milliseconds, with a timeout of 20ms, we would expect 2 retries.
205
214
// crucially, the bug reported in https://github.com/slackapi/node-slack-sdk/issues/2094 shows that on every reconnection attempt, we spawn _another_ websocket instance, which attempts to reconnect forever and is never cleaned up.
206
215
// effectively: with each reconnection attempt, we double the number of websockets, eventually causing crashes / out-of-memory issues / rate-limiting from Slack APIs.
207
216
// with the bug not fixed, this assertion fails as `close` event was emitted 4 times! if we waited another 20ms, we would see this event count double again (8), and so on.
208
-
constretries=closed;
209
217
awaitclient.disconnect();
210
218
awaitnewPromise((res,rej)=>{
211
219
// shut down the bad server
@@ -215,6 +223,7 @@ describe('Integration tests with a WebSocket server', () => {
215
223
});
216
224
});
217
225
assert.equal(retries,2,'unexpected number of times `close` event was raised during reconnection!');
226
+
assert.isAtLeast(elapseTime,25,'unexpectedly rapid `close` events raised during reconnection!');
0 commit comments