@@ -135,6 +135,51 @@ describe('SocketIOTransport', () => {
135135 expect ( subscribeSpy ) . toBeCalledTimes ( 1 )
136136 } )
137137
138+ it ( 'should resubscribe after reconnect' , async ( ) => {
139+ const subscribeCalls : SubscribeCall [ ] = [ ]
140+ const subscribeSpy = jest
141+ . fn ( )
142+ . mockImplementation ( ( subscriptions : string [ ] , callback : SubscribeCallback ) => {
143+ subscribeCalls . push ( { subscriptions, callback } )
144+ } )
145+ mockSocket . clientMock . on ( 'subscribe' , subscribeSpy )
146+
147+ const transport = new SocketIOTransport ( )
148+
149+ transport . streamHandler ( context , emptySubscriptions )
150+ await jest . advanceTimersByTimeAsync ( BACKGROUND_EXECUTE_MS_SSE )
151+
152+ mockSocket . clientMock . emit ( 'connect' )
153+
154+ const subscriptions = [ { base : 'FRAC' , quote : 'USD' } ]
155+ const streamHandlerPromise = transport . streamHandler ( context , {
156+ desired : subscriptions ,
157+ new : subscriptions ,
158+ stale : [ ] ,
159+ } )
160+
161+ expect ( subscribeSpy ) . toBeCalledTimes ( 1 )
162+ expect ( subscribeSpy ) . toBeCalledWith ( [ 'FRAC/USD' ] , expect . any ( Function ) )
163+
164+ subscribeCalls [ 0 ] . callback ( {
165+ status : 'ok' ,
166+ involvedSubscriptions : [ 'frac/usd' ] ,
167+ subscriptionsAfterUpdate : [ 'frac/usd' ] ,
168+ } )
169+ await jest . advanceTimersByTimeAsync ( BACKGROUND_EXECUTE_MS_SSE )
170+ await streamHandlerPromise
171+
172+ // Simulate a reconnect
173+ mockSocket . clientMock . emit ( 'connect' )
174+
175+ transport . streamHandler ( context , { desired : subscriptions , new : [ ] , stale : [ ] } )
176+ await jest . advanceTimersByTimeAsync ( BACKGROUND_EXECUTE_MS_SSE )
177+
178+ // Resubscribed
179+ expect ( subscribeSpy ) . toBeCalledTimes ( 2 )
180+ expect ( subscribeSpy ) . toHaveBeenNthCalledWith ( 2 , [ 'FRAC/USD' ] , expect . any ( Function ) )
181+ } )
182+
138183 it ( 'should unsubscribe' , async ( ) => {
139184 const subscribeCalls : SubscribeCall [ ] = [ ]
140185 const subscribeSpy = jest . fn ( ) . mockImplementation ( ( subscriptions , callback ) => {
0 commit comments