Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0523b65

Browse files
author
Tony Kovanen
committed
Add test for reconnection after server restarts
1 parent ca82c09 commit 0523b65

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/socket.io.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ describe('socket.io', function(){
462462
var c1 = client(srv, '/');
463463
var c2 = client(srv, '/abc');
464464
});
465-
465+
466466
it('should be equivalent for "" and "/" on client', function(done){
467467
var srv = http();
468468
var sio = io(srv);
@@ -471,7 +471,7 @@ describe('socket.io', function(){
471471
});
472472
var c1 = client(srv, '');
473473
});
474-
474+
475475
it('should work with `of` and many sockets', function(done){
476476
var srv = http();
477477
var sio = io(srv);
@@ -1101,6 +1101,32 @@ describe('socket.io', function(){
11011101
});
11021102
});
11031103
});
1104+
1105+
it('should be able to emit after server close and restart', function(done){
1106+
var srv = http();
1107+
var sio = io(srv);
1108+
1109+
sio.on('connection', function(socket){
1110+
socket.on('ev', function(data){
1111+
expect(data).to.be('payload');
1112+
done();
1113+
});
1114+
});
1115+
1116+
srv.listen(function(){
1117+
var port = srv.address().port;
1118+
var clientSocket = client(srv, { reconnectionAttempts: 10, reconnectionDelay: 100 });
1119+
clientSocket.once('connect', function(){
1120+
srv.close(function(){
1121+
srv.listen(port, function(){
1122+
clientSocket.on('reconnect', function(){
1123+
clientSocket.emit('ev', 'payload');
1124+
});
1125+
});
1126+
});
1127+
});
1128+
});
1129+
});
11041130
});
11051131

11061132
describe('messaging many', function(){

0 commit comments

Comments
 (0)