fix: interrupted WebSocket connection not closed by LiveQuery server (#8012)
This commit is contained in:
@@ -23,6 +23,7 @@ describe('ParseWebSocketServer', function () {
|
||||
ws.readyState = 0;
|
||||
ws.OPEN = 0;
|
||||
ws.ping = jasmine.createSpy('ping');
|
||||
ws.terminate = () => {};
|
||||
|
||||
parseWebSocketServer.onConnection(ws);
|
||||
|
||||
@@ -75,6 +76,30 @@ describe('ParseWebSocketServer', function () {
|
||||
expect(wssError).toBe('Invalid Packet');
|
||||
});
|
||||
|
||||
it('closes interrupted connection', async () => {
|
||||
const onConnectCallback = jasmine.createSpy('onConnectCallback');
|
||||
const http = require('http');
|
||||
const server = http.createServer();
|
||||
const parseWebSocketServer = new ParseWebSocketServer(server, onConnectCallback, {
|
||||
websocketTimeout: 5,
|
||||
}).server;
|
||||
const ws = new EventEmitter();
|
||||
ws.readyState = 0;
|
||||
ws.OPEN = 0;
|
||||
ws.ping = jasmine.createSpy('ping');
|
||||
ws.terminate = jasmine.createSpy('terminate');
|
||||
|
||||
parseWebSocketServer.onConnection(ws);
|
||||
|
||||
// Make sure callback is called
|
||||
expect(onConnectCallback).toHaveBeenCalled();
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
expect(ws.ping).toHaveBeenCalled();
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
expect(ws.terminate).toHaveBeenCalled();
|
||||
server.close();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
jasmine.restoreLibrary('ws', 'Server');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user