Improve WebSocketServer Error Handling (#6230)
* Improve WebSocketServer Error Handling Closes: https://github.com/parse-community/parse-server/issues/6173 Prevents an unhandled server rejection. Includes an example for LiveQuery test and closing the proper connections. Improve live query monitoring * fix tests
This commit is contained in:
@@ -39,6 +39,45 @@ describe('ParseWebSocketServer', function() {
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('can handle error event', async () => {
|
||||
jasmine.restoreLibrary('ws', 'Server');
|
||||
const WebSocketServer = require('ws').Server;
|
||||
let wssError;
|
||||
class WSSAdapter {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
onListen() {}
|
||||
onConnection() {}
|
||||
onError() {}
|
||||
start() {
|
||||
const wss = new WebSocketServer({ server: this.options.server });
|
||||
wss.on('listening', this.onListen);
|
||||
wss.on('connection', this.onConnection);
|
||||
wss.on('error', error => {
|
||||
wssError = error;
|
||||
this.onError(error);
|
||||
});
|
||||
this.wss = wss;
|
||||
}
|
||||
}
|
||||
|
||||
const server = await reconfigureServer({
|
||||
liveQuery: {
|
||||
classNames: ['TestObject'],
|
||||
},
|
||||
liveQueryServerOptions: {
|
||||
wssAdapter: WSSAdapter,
|
||||
},
|
||||
startLiveQueryServer: true,
|
||||
verbose: false,
|
||||
silent: true,
|
||||
});
|
||||
const wssAdapter = server.liveQueryServer.parseWebSocketServer.server;
|
||||
wssAdapter.wss.emit('error', 'Invalid Packet');
|
||||
expect(wssError).toBe('Invalid Packet');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
jasmine.restoreLibrary('ws', 'Server');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user