@@ -791,32 +791,6 @@ describe('StreamrClient', function() {
791791 } )
792792 } )
793793 } )
794- } )
795-
796- describe ( "disconnect" , function ( ) {
797-
798- it ( 'should disconnect the socket' , function ( done ) {
799- client . connect ( )
800- client . socket . disconnect = done
801-
802- client . socket . once ( 'connect' , function ( ) {
803- client . disconnect ( )
804- } )
805- } )
806-
807- it ( 'should report that it is not connected and not connecting after disconnecting' , function ( done ) {
808- client . connect ( )
809-
810- client . socket . once ( 'connect' , function ( ) {
811- client . disconnect ( )
812- } )
813-
814- client . socket . once ( 'disconnect' , function ( ) {
815- assert ( ! client . isConnected ( ) )
816- assert ( ! client . connecting )
817- done ( )
818- } )
819- } )
820794
821795 it ( 'should disconnect when no longer subscribed to any streams' , function ( done ) {
822796 client . options . autoDisconnect = true
@@ -839,6 +813,30 @@ describe('StreamrClient', function() {
839813 } )
840814 } )
841815
816+ it ( 'should disconnect if all subscriptions are done during resend' , function ( done ) {
817+ client . options . autoDisconnect = true
818+
819+ var sub1 = client . subscribe ( "stream1" , function ( message ) { } , { resend_all : true } )
820+ client . connect ( )
821+
822+ client . socket . on ( 'resend' , function ( request ) {
823+ async ( function ( ) {
824+ client . socket . emit ( 'resending' , {
825+ channel : request . channel ,
826+ sub : request . sub ,
827+ from : 0 ,
828+ to : 0
829+ } )
830+ client . socket . emit ( 'ui' , byeMsg ( request . channel , 0 ) )
831+ client . socket . emit ( 'resent' , { channel : request . channel , sub : request . sub , from :0 , to :0 } )
832+ } )
833+ } )
834+
835+ client . socket . on ( 'disconnect' , function ( ) {
836+ done ( )
837+ } )
838+ } )
839+
842840 it ( 'should not disconnect if autoDisconnect is set to false' , function ( done ) {
843841 client . options . autoDisconnect = false
844842
@@ -858,6 +856,32 @@ describe('StreamrClient', function() {
858856 throw "Should not have disconnected!"
859857 } )
860858 } )
859+ } )
860+
861+ describe ( "disconnect" , function ( ) {
862+
863+ it ( 'should disconnect the socket' , function ( done ) {
864+ client . connect ( )
865+ client . socket . disconnect = done
866+
867+ client . socket . once ( 'connect' , function ( ) {
868+ client . disconnect ( )
869+ } )
870+ } )
871+
872+ it ( 'should report that it is not connected and not connecting after disconnecting' , function ( done ) {
873+ client . connect ( )
874+
875+ client . socket . once ( 'connect' , function ( ) {
876+ client . disconnect ( )
877+ } )
878+
879+ client . socket . once ( 'disconnect' , function ( ) {
880+ assert ( ! client . isConnected ( ) )
881+ assert ( ! client . connecting )
882+ done ( )
883+ } )
884+ } )
861885
862886 it ( 'should reset subscriptions when calling disconnect()' , function ( done ) {
863887 client . subscribe ( "stream1" , function ( message ) { } )
0 commit comments