Skip to content

Commit a0ddae5

Browse files
committed
Add test to verify order of unsubscribe/disonnect events
1 parent 3c252e0 commit a0ddae5

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

test/integration.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,52 @@ describe('Integration tests', function () {
10481048
}, 300);
10491049
});
10501050
});
1051+
1052+
it('Unsubscribe event should trigger before private _disconnect event', function (done) {
1053+
portNumber++;
1054+
server = socketClusterServer.listen(portNumber, {
1055+
authKey: serverOptions.authKey
1056+
});
1057+
1058+
var eventList = [];
1059+
1060+
server.on('connection', function (socket) {
1061+
socket.on('unsubscribe', function (channel) {
1062+
eventList.push({
1063+
type: 'unsubscribe',
1064+
channel: channel
1065+
});
1066+
});
1067+
socket.on('_disconnect', function (code, reason) {
1068+
eventList.push({
1069+
type: '_disconnect',
1070+
code: code,
1071+
reason: reason
1072+
});
1073+
assert.equal(eventList[0].type, 'unsubscribe');
1074+
assert.equal(eventList[0].channel, 'foo');
1075+
assert.equal(eventList[1].type, '_disconnect');
1076+
1077+
done();
1078+
});
1079+
});
1080+
1081+
server.on('ready', function () {
1082+
client = socketCluster.connect({
1083+
hostname: clientOptions.hostname,
1084+
port: portNumber,
1085+
multiplex: false
1086+
});
1087+
1088+
client.subscribe('foo').on('subscribe', function () {
1089+
setTimeout(function () {
1090+
client.disconnect();
1091+
}, 50);
1092+
});
1093+
});
1094+
});
10511095
});
1096+
10521097
describe('Middleware', function () {
10531098
var middlewareFunction;
10541099
var middlewareWasExecuted = false;
@@ -1070,7 +1115,6 @@ describe('Integration tests', function () {
10701115
});
10711116
});
10721117

1073-
10741118
describe('MIDDLEWARE_AUTHENTICATE', function () {
10751119
it('Should not run authenticate middleware if JWT token does not exist', function (done) {
10761120
middlewareFunction = function (req, next) {

0 commit comments

Comments
 (0)