@@ -1048,7 +1048,52 @@ describe('Integration tests', function () {
1048
1048
} , 300 ) ;
1049
1049
} ) ;
1050
1050
} ) ;
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
+ } ) ;
1051
1095
} ) ;
1096
+
1052
1097
describe ( 'Middleware' , function ( ) {
1053
1098
var middlewareFunction ;
1054
1099
var middlewareWasExecuted = false ;
@@ -1070,7 +1115,6 @@ describe('Integration tests', function () {
1070
1115
} ) ;
1071
1116
} ) ;
1072
1117
1073
-
1074
1118
describe ( 'MIDDLEWARE_AUTHENTICATE' , function ( ) {
1075
1119
it ( 'Should not run authenticate middleware if JWT token does not exist' , function ( done ) {
1076
1120
middlewareFunction = function ( req , next ) {
0 commit comments