@@ -894,7 +894,7 @@ describe('integration tests', function () {
894894 } ) ;
895895 } ) ;
896896
897- describe ( 'order of local events' , function ( ) {
897+ describe ( 'order of events' , function ( ) {
898898 it ( 'should trigger unsubscribe event on channel before disconnect event' , function ( done ) {
899899 client = socketClusterClient . create ( clientOptions ) ;
900900 var hasUnsubscribed = false ;
@@ -1026,8 +1026,124 @@ describe('integration tests', function () {
10261026 } , 1000 ) ;
10271027 } ) ;
10281028
1029- it ( 'TODO: should throw an error if emit is called on a destroyed socket' , function ( done ) {
1029+ it ( 'should reactivate and reconnect socket if emit is called on a destroyed socket' , function ( done ) {
1030+ client = socketClusterClient . create ( clientOptions ) ;
1031+ assert . equal ( client . active , true ) ;
1032+
1033+ var clientError ;
1034+ client . on ( 'error' , function ( err ) {
1035+ clientError = err ;
1036+ } ) ;
1037+
1038+ client . once ( 'connect' , function ( ) {
1039+ assert . equal ( client . active , true ) ;
1040+ client . destroy ( ) ;
1041+ assert . equal ( client . active , false ) ;
1042+
1043+ client . once ( 'connect' , function ( ) {
1044+ assert . equal ( client . active , true ) ;
1045+ done ( ) ;
1046+ } ) ;
1047+
1048+ client . emit ( 'foo' , 123 ) ;
1049+
1050+ assert . equal ( client . active , true ) ;
1051+ assert . equal ( client . state , client . CONNECTING ) ;
1052+ } ) ;
1053+ } ) ;
1054+
1055+ it ( 'should correctly handle multiple successive connect and disconnect calls' , function ( done ) {
1056+ client = socketClusterClient . create ( clientOptions ) ;
1057+
1058+ var eventList = [ ] ;
1059+
1060+ var clientError ;
1061+ client . on ( 'error' , function ( err ) {
1062+ clientError = err ;
1063+ } ) ;
1064+ client . on ( 'connecting' , function ( ) {
1065+ eventList . push ( {
1066+ event : 'connecting'
1067+ } ) ;
1068+ } ) ;
1069+ client . on ( 'connect' , function ( ) {
1070+ eventList . push ( {
1071+ event : 'connect'
1072+ } ) ;
1073+ } ) ;
1074+ client . on ( 'connectAbort' , function ( code , reason ) {
1075+ eventList . push ( {
1076+ event : 'connectAbort' ,
1077+ code : code ,
1078+ reason : reason
1079+ } ) ;
1080+ } ) ;
1081+ client . on ( 'disconnect' , function ( code , reason ) {
1082+ eventList . push ( {
1083+ event : 'disconnect' ,
1084+ code : code ,
1085+ reason : reason
1086+ } ) ;
1087+ } ) ;
1088+ client . on ( 'close' , function ( code , reason ) {
1089+ eventList . push ( {
1090+ event : 'close' ,
1091+ code : code ,
1092+ reason : reason
1093+ } ) ;
1094+ } ) ;
1095+
1096+ client . disconnect ( 1000 , 'One' ) ;
1097+ client . connect ( ) ;
1098+ client . disconnect ( 4444 , 'Two' ) ;
1099+ client . once ( 'connect' , function ( ) {
1100+ client . disconnect ( 4455 , 'Three' ) ;
1101+ } ) ;
1102+ client . connect ( ) ;
1103+
10301104 setTimeout ( function ( ) {
1105+ var expectedEventList = [
1106+ {
1107+ event : 'connectAbort' ,
1108+ code : 1000 ,
1109+ reason : 'One'
1110+ } ,
1111+ {
1112+ event : 'close' ,
1113+ code : 1000 ,
1114+ reason : 'One'
1115+ } ,
1116+ {
1117+ event : 'connecting'
1118+ } ,
1119+ {
1120+ event : 'connectAbort' ,
1121+ code : 4444 ,
1122+ reason : 'Two'
1123+ } ,
1124+ {
1125+ event : 'close' ,
1126+ code : 4444 ,
1127+ reason : 'Two'
1128+ } ,
1129+ {
1130+ event : 'connecting'
1131+ } ,
1132+ {
1133+ event : 'connect'
1134+ } ,
1135+ {
1136+ event : 'disconnect' ,
1137+ code : 4455 ,
1138+ reason : 'Three'
1139+ } ,
1140+ {
1141+ event : 'close' ,
1142+ code : 4455 ,
1143+ reason : 'Three'
1144+ } ,
1145+ ] ;
1146+ assert . equal ( JSON . stringify ( eventList ) , JSON . stringify ( expectedEventList ) ) ;
10311147 done ( ) ;
10321148 } , 200 ) ;
10331149 } ) ;
0 commit comments