Waiting for database connection before accepting requests - node.js

The problem that I have is that my express server starts before the database connection is established. People can send requests to the application while the connection is not yet there for some time:
const app = express();
dbClient.connect()
.subscribe(() => console.log('connection established!'));
module.exports = app.listen(8080, () => {
console.log('the server is running');
});
The outcome of this is:
the server is running // some seconds break
connection established! // now everything works properly
How can I start listening to events only after the subscriber has been run?

The only way to ensure you are connected before to listen is to chain it. If you experience trouble about exporting the result is because you are mistaking import/export. Import/export should not have any impact on your system. Every actions should be triggered and not implied.
You should consider putting all your Express handling into a class and then use it in your controller. This way you could handle errors ... As example :
// File a.js
let instance = null;
export default class ServerApi {
constructor() {
if (instance) return instance;
instance = this;
return instance;
}
static getInstance() {
return instance || new ServerApi();
}
startServer(callback) {
const app = express();
dbClient.connect()
.subscribe(() => {
console.log('connection established!');
app.listen(8080, () => {
console.log('the server is running');
callback();
});
});
}
stopServer() { ... }
getServerStatus() { ... }
};
// File controller.js
import ServerApi from 'a.js';
ServerApi.getInstance().startServer(() => {
// handle error
// handle success
});

There are few ways to achieve this.
one a ways to wrap app.listen into observable
const app = express();
const connectApp = (port = 8080) => new Observable(observer => app.listen(port, () => {
observer.next(app);
observer.complete();
});
dbClient.connect()
.pipe(
tap(() => console.log('connection established!')),
mergeMap(() => connectApp()),
tap(() => console.log('the server is running')),
)
.subscribe(() => console.log('Enjoy'));

Related

Unit Test with Express / Mocha / Mongodb Memory Server

I would like to configure my project in order to run unit test for some API endpoints (that call the database). I'm using :
ExpressJS
MongoDB (no Mongoose)
Mocha / Chai
Mongodb Memory Server (to mock the DB)
// app.ts
export const app = express();
const port = process.env.PORT;
app.use("/my-route", myRoutes);
mongoConnect().then(() => {
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
});
// database.ts
export const mongoConnect = async () => {
try {
let MONGODB_URI = process.env.MONGODB_URI;
if (process.env.NODE_ENV === "test") {
const mongoServer = await MongoMemoryServer.create();
MONGODB_URI = mongoServer.getUri();
}
const client: MongoClient = await MongoClient.connect(MONGODB_URI);
_db = client.db("dbName");
_mongoClient = client;
if (process.env.NODE_ENV === "test") {
console.log("Connected to MongoDB Test");
} else {
console.log("Connected to MongoDB");
}
} catch (err) {
console.log("Error connecting to MongoDB:", err);
throw err;
}
};
export const getMongoClient = () => {
if (_mongoClient) {
return _mongoClient;
}
throw "Mongo client doesn't exist";
};
export const getDb = () => {
if (_db) {
return _db;
}
throw "No database found!";
};
// test.ts
let mongoClient: MongoClient;
let db: Db;
before(function (done) {
mongoConnect()
.then(() => {
db = getDb();
mongoClient = getMongoClient();
return db.createCollection("wordsCollection");
})
.then(() => {
db.collection("wordsCollection").insertMany(data);
})
.catch((err) => console.log(err))
.finally(() => done());
});
after(function (done) {
db.dropDatabase();
mongoClient.close().then(() => {
done();
});
});
it("test", async function () {
let res = await chai
.request(app)
.post("/my-route/hello")
.send({ excludeIds: [] });
expect(res.status).to.equal(200);
});
});
But it's not working...
If I call mongoConnect() in test.ts it console.log twice Connected to MongoDB Test. But if I don't call the function it throws me error because MongoClient is undefined.
I think await chai.request(app) already calls the database and server but I need to create Collection and Documents before. So I need to connect to the DB before the test.
Any help would be greatly appreciated.
I found a solution, I don't know if it's best practice but it works and is pretty easy, thanks to this post : https://stackoverflow.com/a/70285190/10547153.
I needed to add a condition in app.ts before making the connection to the database and the server in order to launch them only if it's called by Node itself.
if (require.main === module) {
mongoConnect().then(() => {
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
});
}
When a file is run directly from Node.js, require.main is set to its
module. That means that it is possible to determine whether a file has
been run directly by testing require.main === module.
Now I can connect to the mocked database from test.ts and only one connection will be triggered.

Testing sockets with Mocha

I'm starting to learn how to test and I'm having some troubles.
I'm trying to run tests on a socket server but I'm not able to send any message, just connecting an receiving sometimes.
Here is what I have:
import { expect } from 'chai';
import { io as Client } from 'socket.io-client';
import { httpServer } from '../src/loader/app.js';
let server;
let socketUrl;
describe('Sockets test cycle', () => {
before(async function () {
server = await startServer();
socketUrl = `http://localhost:${server.address().port}`;
});
after(function () {
server.close();
});
describe('SOCKET', () => {
it('Should receive a message', async () => {
const client = new Client(socketUrl);
const message = {
text: 'Test',
username: 'test#test',
};
client.on('messages', (arg, done) => {
console.log('Receiving message');
expect(arg).to.eql(message);
client.disconnect();
done();
});
//Only with this await I'm able to connect to server.
//await new Promise((r) => setTimeout(r, 1000));
client.on('connect', () => {
client.emit('new-message', message);
console.log('Sending message');
});
});
});
});
async function startServer() {
return new Promise((resolve, reject) => {
const PORT = 0;
const server = httpServer.listen(PORT, () => {
console.log(`Server listening on port ${server.address().port}`);
resolve(server);
});
server.on('error', (error) => {
console.log(`Error on server: ${error}`);
reject(error);
});
});
}
EDIT:
Here is the output:
[2022-04-03T23:03:58.979] [INFO] default - Starting Products Router
[2022-04-03T23:03:58.981] [INFO] default - Starting Carts Router
[2022-04-03T23:03:58.982] [INFO] default - Starting Users Router
[2022-04-03T23:03:58.982] [INFO] default - Starting Orders Router
[2022-04-03T23:03:58.984] [INFO] default - Starting MessageSocketRouter
Sockets test cycle
Server listening on port 53178
SOCKET
✔ Should receive a message
1 passing (20ms)
If I add the await in the middle with 1 second for waiting, I'm able to connect, but that's all I could do.
Could you give me any idea or any hint? I've been reading the oficial documentation but I'm kind of lost.
Thanks!

Nuxt, Express, Sockets can't get connection

Im try in to create a little app and wanted to add websockets to it but im having some issues getting a connection. Im using the nuxt-socket-io and socket io.
const socket = require('socket.io')
// Options can be host, port, ioSvc, nspDir:
module.exports = (app) => {
let server = null
let io = null
app.use('/ws', (req, res) => {
if (!server) {
server = res.connection.server
io = socket(server)
io.on('connection', function (socket) {
console.log('Made socket connection')
socket.on('msg', (msg) => {
console.log('Recived: ' + msg)
setTimeout(() => {
socket.emit('msg', `Response to: ${msg}`)
}, 1000)
})
socket.on('disconnect', () => console.log('disconnected'))
})
}
res.json({ msg: 'server is set' })
})
}
this is being used to create the sockets on the server
and my nuxt-config is
['nuxt-socket-io', {
sockets: [ // Required
{ // At least one entry is required
name: 'main',
url: 'http://localhost:3000/api/ws',
path: 'ws',
default: true
}
],
server: false
}],
then in my .vue file
mounted () {
this.socket = this.$nuxtSocket({
path: '/api/ws'
})
},
methods: {
callSocket () {
console.log('trying to call socket')
this.socket.emit('msg', 'test message', (resp) => {
console.log(resp)
this.resp = resp
})
}
}
I get a response from the server
{"msg":"server is set"}
but I never get to the connection
console.log('Made socket connection')
but I can't seem to get connected to run any of the emits and i'm not sure why
you can see the full code repo at https://github.com/Chris9540/mappertron
if that will help give you more of an idea of what going on
This is my first time trying to add sockets so I may may done this completely wrong feel free to fork my branch with any alterations you suggest if I'm doing this completely wrong
I've manage to get it working by just using socket-io and socket.io-client see the I mainly followed this guide https://stackoverflow.com/a/65226573/7805726 see the repo for more details (https://github.com/Chris9540/mappertron) I would still like to get it working with nuxt-socket-io but I have sockets so im happy
for my fix I abstracted out some of the app set up to a new file
const app = require('express')()
const socket = require('socket.io')
const bodyParser = require('body-parser')
let server = null
let io = null
app.all('/ws', (req, res) => {
if (!server) {
server = res.connection.server
io = socket(server)
io.on('connection', function (socket) {
console.log('Made socket connection')
socket.on('msg', (msg) => {
console.log('Recived: ' + msg)
setTimeout(() => {
socket.emit('msg', `Response to: ${msg}`)
}, 1000)
})
socket.on('disconnect', () => console.log('disconnected'))
})
}
res.json({ msg: 'server is set' })
})
app.use(bodyParser.json())
module.exports = app
got rid of the nuxt-socket-io configs
and in my vue
this.$axios.$get('/api/ws')
.then((resp) => {
// eslint-disable-next-line no-undef
this.socket = io()
this.socket.on('msg', function (msg) {
console.log('socket responce', msg)
this.resps += `${msg}\n`
})
})
and
this.socket.emit('msg', JSON.stringify({ id: 1, x: 1, y: 1 }))

node-mssql "connection is closed" when running Mocha test, but runs fine in app

I have a node.js data processing app that pulls some data from mssql. It runs fine and produces the expected results. However, the integration tests aren't working and I would like them to.
Below is the connection management and a test query function. I can see from output and running in the debugger that the test has run and failed before the database has connected. So it seems like my Mocha async setup isn't working, but it looks like everything I've seen in documentation.
node -v
v10.15.0
chai: "^4.2.0",
mocha: "^5.2.0"
mssql: "^4.3.0",
const config = require('./config')
const _ = require('underscore')
const sql = require('mssql')
sql.on('error', err => {
console.error('SQL Error', err)
})
let api = {}
api.connect = async dbConfig => {
return new sql.ConnectionPool(dbConfig).connect(
err => {
if (err)
console.error('Connection error', err)
else
console.log('connected')
})
}
var connecting = api.connect(config.sql)
api.simple = async () => {
let pool = await connecting
let result = await pool.request().query('select 1 as number')
return result.recordset[0].number
}
module.exports = api
Here is my mocha test for it that fails
const { expect } = require('chai')
const data = require('../src/data')
describe('data access', function () {
it('is simple', async function () {
const yo = await data.simple()
expect(yo).to.exist
expect(yo).to.equal(1)
})
})
I've also tried the older style of async mocha tests using done callbacks ala
it('is simple oldschool', function (done) {
data.simple()
.then(function(yo){
expect(yo).to.exist
expect(yo).to.equal(1)
done()
})
})
That times out no matter how long I set Mocha's timeout for (I tried as high as 60 seconds)
I'm at my wits end here, anyone see anything wrong?
api.connect can return before the connection is actually done. Rewriting it like this will make sure ConnectionPool.connect can finish before the api.connect promise resolves.
api.connect = dbConfig =>
new Promise((resolve, reject) => {
const pool = new sql.ConnectionPool(dbConfig);
pool.connect(err => {
if (err) {
console.error("Connection error", err);
return reject(err);
}
return resolve(pool);
});
});
Beyond that, I'm confused about let pool = await c3; there's no symbol c3 in the code you've pasted...
I think you are having a race condition with the database connection.
I do this in the before()
before((done) => {
server.on("serverStarted", function() {
done();
});
});
Then in my server (I'm using node), I emit when when I am connected:
var port = process.env.PORT || 3030;
var server = http.listen(port, function(){
console.log('listening on port: ' + port);
db.connect().then(() => {
console.log("Connect to database successful");
server.emit("serverStarted") // HERE IT IS
}).catch(err => {
console.error(err);
console.log("Cannot connect to database");
process.exit(1);
});
});
Hope this helps. I've pulled out some hair on this one.

Unit testing Node.js and WebSockets (Socket.io)

Could anyone provide a rock-solid, dead-simple unit test for Node.js using WebSockets (Socket.io)?
I'm using socket.io for Node.js, and have looked at socket.io-client for establishing the client connection to a server in the test. However, I seem to be missing something.
In the example below, "worked..." never gets printed out.
var io = require('socket.io-client')
, assert = require('assert')
, expect = require('expect.js');
describe('Suite of unit tests', function() {
describe('First (hopefully useful) test', function() {
var socket = io.connect('http://localhost:3001');
socket.on('connect', function(done) {
console.log('worked...');
done();
});
it('Doing some things with indexOf()', function() {
expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
expect([1, 2, 3].indexOf(0)).to.be.equal(-1);
});
});
});
Instead, I simply get:
Suite of unit tests
First (hopefully useful) test
✓ Doing some things with indexOf()
1 test complete (26 ms)
Any suggestions?
After further poking and prodding, I found some incredibly useful information. In the author's example, he points out the critical step of establishing socket listeners in the before hooks.
This example works:
Assuming a server is listening for socket connections at localhost:3001, of course
var io = require('socket.io-client')
, assert = require('assert')
, expect = require('expect.js');
describe('Suite of unit tests', function() {
var socket;
beforeEach(function(done) {
// Setup
socket = io.connect('http://localhost:3001', {
'reconnection delay' : 0
, 'reopen delay' : 0
, 'force new connection' : true
});
socket.on('connect', function() {
console.log('worked...');
done();
});
socket.on('disconnect', function() {
console.log('disconnected...');
})
});
afterEach(function(done) {
// Cleanup
if(socket.connected) {
console.log('disconnecting...');
socket.disconnect();
} else {
// There will not be a connection unless you have done() in beforeEach, socket.on('connect'...)
console.log('no connection to break...');
}
done();
});
describe('First (hopefully useful) test', function() {
it('Doing some things with indexOf()', function(done) {
expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
expect([1, 2, 3].indexOf(0)).to.be.equal(-1);
done();
});
it('Doing something else with indexOf()', function(done) {
expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
expect([1, 2, 3].indexOf(0)).to.be.equal(-1);
done();
});
});
});
I found that the placement of done() in the beforeEach, socket.on('connect'...) listener was crucial to having the connection get established. For example, if you comment out done() in the listener, then add it one scope out (just before exiting the beforeEach), you'll see the "no connection to break..." message instead of the "disconnecting..." message. Like so:
beforeEach(function(done) {
// Setup
socket = io.connect('http://localhost:3001', {
'reconnection delay' : 0
, 'reopen delay' : 0
, 'force new connection' : true
});
socket.on('connect', function() {
console.log('worked...');
//done();
});
socket.on('disconnect', function() {
console.log('disconnected...');
});
done();
});
I'm new to Mocha, so there's probably a very obvious reason to the initiated for placing done() within the socket scope itself. Hopefully that little detail will save others in my shoes from hair pulling.
For me, the above test (with correct scoping of done()) outputs:
Suite of unit tests
First (hopefully useful) test
◦ Doing some things with indexOf(): worked...
✓ Doing some things with indexOf()
disconnecting...
disconnected...
◦ Doing something else with indexOf(): worked...
✓ Doing something else with indexOf()
disconnecting...
disconnected...
2 tests complete (93 ms)
Offering an extension of the accepted answer here. Has basic client to server communication useful as boilerplate for other future tests. Using mocha, chai, and expect.
var io = require('socket.io-client')
, io_server = require('socket.io').listen(3001);
describe('basic socket.io example', function() {
var socket;
beforeEach(function(done) {
// Setup
socket = io.connect('http://localhost:3001', {
'reconnection delay' : 0
, 'reopen delay' : 0
, 'force new connection' : true
, transports: ['websocket']
});
socket.on('connect', () => {
done();
});
socket.on('disconnect', () => {
// console.log('disconnected...');
});
});
afterEach((done) => {
// Cleanup
if(socket.connected) {
socket.disconnect();
}
io_server.close();
done();
});
it('should communicate', (done) => {
// once connected, emit Hello World
io_server.emit('echo', 'Hello World');
socket.once('echo', (message) => {
// Check that the message matches
expect(message).to.equal('Hello World');
done();
});
io_server.on('connection', (socket) => {
expect(socket).to.not.be.null;
});
});
});
Dealing with callbacks and promises yourself can be difficult and non trivial examples quickly become very complex and hard to read.
There is a tool called socket.io-await-test available via NPM that allows you to suspend/wait in a test until events have been triggered using the await keyword.
describe("wait for tests", () => {
it("resolves when a number of events are received", async () => {
const tester = new SocketTester(client);
const pongs = tester.on('pong');
client.emit('ping', 1);
client.emit('ping', 2);
await pongs.waitForEvents(2) // Blocks until the server emits "pong" twice.
assert.equal(pongs.get(0), 2)
assert.equal(pongs.get(1), 3)
})
})
Check out this boilerplate solution that's based on promises and good practice.
You can test your servers entire io events with it, no sweat.
You just need to copy a boilerplate test and add your own code as needed.
Checkout the repo on GitHub for full source code.
https://github.com/PatMan10/testing_socketIO_server
const io = require("socket.io-client");
const ev = require("../utils/events");
const logger = require("../utils/logger");
// initSocket returns a promise
// success: resolve a new socket object
// fail: reject a error
const initSocket = () => {
return new Promise((resolve, reject) => {
// create socket for communication
const socket = io("localhost:5000", {
"reconnection delay": 0,
"reopen delay": 0,
"force new connection": true
});
// define event handler for sucessfull connection
socket.on(ev.CONNECT, () => {
logger.info("connected");
resolve(socket);
});
// if connection takes longer than 5 seconds throw error
setTimeout(() => {
reject(new Error("Failed to connect wihtin 5 seconds."));
}, 5000);
}
);
};
// destroySocket returns a promise
// success: resolve true
// fail: resolve false
const destroySocket = socket => {
return new Promise((resolve, reject) => {
// check if socket connected
if (socket.connected) {
// disconnect socket
logger.info("disconnecting...");
socket.disconnect();
resolve(true);
} else {
// not connected
logger.info("no connection to break...");
resolve(false);
}
});
};
describe("test suit: Echo & Bello", () => {
test("test: ECHO", async () => {
// create socket for communication
const socketClient = await initSocket();
// create new promise for server response
const serverResponse = new Promise((resolve, reject) => {
// define a handler for the test event
socketClient.on(ev.res_ECHO, data4Client => {
//process data received from server
const { message } = data4Client;
logger.info("Server says: " + message);
// destroy socket after server responds
destroySocket(socketClient);
// return data for testing
resolve(data4Client);
});
// if response takes longer than 5 seconds throw error
setTimeout(() => {
reject(new Error("Failed to get reponse, connection timed out..."));
}, 5000);
});
// define data 4 server
const data4Server = { message: "CLIENT ECHO" };
// emit event with data to server
logger.info("Emitting ECHO event");
socketClient.emit(ev.com_ECHO, data4Server);
// wait for server to respond
const { status, message } = await serverResponse;
// check the response data
expect(status).toBe(200);
expect(message).toBe("SERVER ECHO");
});
test("test BELLO", async () => {
const socketClient = await initSocket();
const serverResponse = new Promise((resolve, reject) => {
socketClient.on(ev.res_BELLO, data4Client => {
const { message } = data4Client;
logger.info("Server says: " + message);
destroySocket(socketClient);
resolve(data4Client);
});
setTimeout(() => {
reject(new Error("Failed to get reponse, connection timed out..."));
}, 5000);
});
const data4Server = { message: "CLIENT BELLO" };
logger.info("Emitting BELLO event");
socketClient.emit(ev.com_BELLO, data4Server);
const { status, message } = await serverResponse;
expect(status).toBe(200);
expect(message).toBe("SERVER BELLO");
});
});
---- Foot Note ----
Depending on how you setup your server environment, you may experience environmental conflict between socket.io and socket.io-client running from the same project simultaneously. In which case it would be better to separate the project into a "test client" and a server. Checkout below repo if you get this issue.
https://github.com/PatMan10/testing_socketIO_server_v2
In OP's code,
socket.on('connect', function(done) {
console.log('worked...');
done();
});
the done was applied to the wrong callback. It should be removed from the socket.on callback and added to Mocha's it block callback:
it('First (hopefully useful) test', function (done) {
var socket = io.connect('http://localhost:3001');
socket.on('connect', function () {
console.log('worked...');
done();
});
});
A complete example
Existing answers are great but don't show the server ultimately being tested. Here's a complete version with console.logs to illustrate what's going on. Explanation follows.
src/server.js:
const express = require("express");
const createServer = (port=3000) => {
const app = express();
const http = require("http").Server(app);
const io = require("socket.io")(http);
io.on("connection", socket => {
console.log("[server] user connected");
socket.on("message", msg => {
console.log(`[server] received '${msg}'`);
socket.emit("message", msg);
});
socket.on("disconnect", () => {
console.log("[server] user disconnected");
});
});
http.listen(port, () =>
console.log(`[server] listening on port ${port}`)
);
return {
close: () => http.close(() =>
console.log("[server] closed")
)
};
};
module.exports = {createServer};
test/server.test.js:
const {expect} = require("chai");
const io = require("socket.io-client");
const {createServer} = require("../src/server");
const socketUrl = "http://localhost:3000";
describe("server", function () {
this.timeout(3000);
let server;
let sockets;
beforeEach(() => {
sockets = [];
server = createServer();
});
afterEach(() => {
sockets.forEach(e => e.disconnect())
server.close();
});
const makeSocket = (id=0) => {
const socket = io.connect(socketUrl, {
"reconnection delay": 0,
"reopen delay": 0,
"force new connection": true,
transports: ["websocket"],
});
socket.on("connect", () => {
console.log(`[client ${id}] connected`);
});
socket.on("disconnect", () => {
console.log(`[client ${id}] disconnected`);
});
sockets.push(socket);
return socket;
};
it("should echo a message to a client", done => {
const socket = makeSocket();
socket.emit("message", "hello world");
socket.on("message", msg => {
console.log(`[client] received '${msg}'`);
expect(msg).to.equal("hello world");
done();
});
});
it("should echo messages to multiple clients", () => {
const sockets = [...Array(5)].map((_, i) => makeSocket(i));
return Promise.all(sockets.map((socket, id) =>
new Promise((resolve, reject) => {
const msgs = [..."abcd"].map(e => e + id);
msgs.slice().forEach(e => socket.emit("message", e));
socket.on("message", msg => {
console.log(`[client ${id}] received '${msg}'`);
expect(msg).to.equal(msgs.shift());
if (msgs.length === 0) {
resolve();
}
});
})
));
});
});
In summary, the server exports a function that lets a server app be created from scratch, allowing each it block to be idempotent and avoid server state from carrying between tests (assuming no persistence on the server otherwise). Creating an app returns an object with a close function. socket.disconnect() must be called per socket in each test to avoid timeouts.
Given these requirements, the testing suite follows this per-test setup/teardown workflow:
let server;
let sockets;
beforeEach(() => {
sockets = [];
server = createServer();
});
afterEach(() => {
sockets.forEach(e => e.disconnect())
server.close();
});
makeSocket is an optional helper to reduce the repeated boilerplate of connecting and disconnecting a socket client. It does produce a side effect on the sockets array for cleanup later, but this is an implementation detail from the it block's perspective. Test blocks shoudn't touch server or sockets variables, although other workflows are likely depending on need. The critical takeaways are test case idempotency and closing all connections after each test case.
Options on the socket.connect object on the client let you choose transport and behavior of the socket. "force new connection": true creates a new Manager per socket instead of reusing an existing one and transports: ["websocket"] upgrades to WS protocol from long polling immediately.
Use it("should ... ", done => { /* tests */ }); and invoke done() after all work is completed in callbacks or return a promise (and omit the done parameter to the it callback). The example above shows both approaches.
Used in this post:
node: 12.19.0
chai: 4.2.0
express: 4.16.4
mocha: 5.2.0
socket.io: 2.2.0
socket.io-client: 2.2.0
I had this problem: How to do unit test with a "socket.io-client" if you don't know how long the server take to respond?.
I've solved so using mocha and chai:
var os = require('os');
var should = require("chai").should();
var socketio_client = require('socket.io-client');
var end_point = 'http://' + os.hostname() + ':8081';
var opts = {forceNew: true};
describe("async test with socket.io", function () {
this.timeout(10000);
it('Response should be an object', function (done) {
setTimeout(function () {
var socket_client = socketio_client(end_point, opts);
socket_client.emit('event', 'ABCDEF');
socket_client.on('event response', function (data) {
data.should.be.an('object');
socket_client.disconnect();
done();
});
socket_client.on('event response error', function (data) {
console.error(data);
socket_client.disconnect();
done();
});
}, 4000);
});
});

Resources