File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+
3+ import onErrorResumeNext from 'on-error-resume-next' ;
4+
5+ import { timeouts } from './constants.json' ;
6+ import * as createDirectLine from './setup/createDirectLine' ;
7+ import waitForConnected from './setup/waitForConnected' ;
8+
9+ // TODO: Need more realistic testing.
10+ // - Able to connect to a Web Socket server
11+ // - Make sure after `end` is called, the client will not reconnect
12+ // - If the connection is disrupted, make sure the client will reconnect
13+ // - Use a fake timer to speed up the test
14+ describe ( 'test dl streaming end' , ( ) => {
15+ let unsubscribes ;
16+ let directLine ;
17+ const ConnectionStatusEnd = 5 ;
18+ beforeEach ( ( ) => unsubscribes = [ ] ) ;
19+ afterEach ( ( ) => unsubscribes . forEach ( fn => onErrorResumeNext ( fn ) ) ) ;
20+ test ( 'using Streaming Extensions' , async ( ) => {
21+ jest . setTimeout ( 30000 ) ;
22+ directLine = await createDirectLine . forStreamingExtensions ( ) ;
23+ unsubscribes . push ( directLine . end . bind ( directLine ) ) ;
24+ unsubscribes . push ( await waitForConnected ( directLine ) ) ;
25+ await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
26+ directLine . end ( ) ;
27+ expect ( directLine . connectionStatus$ . getValue ( ) ) . toBe ( ConnectionStatusEnd ) ;
28+ } )
29+ } ) ;
Original file line number Diff line number Diff line change @@ -316,6 +316,10 @@ export class DirectLineStreaming implements IBotConnection {
316316 try {
317317 this . connectionStatus$ . next ( ConnectionStatus . Connecting ) ;
318318 const res = await this . connectAsync ( ) ;
319+ if ( this . connectionStatus$ . getValue ( ) === ConnectionStatus . Ended ) {
320+ console . warn ( 'Connection end' ) ;
321+ break ;
322+ }
319323 console . warn ( `Retrying connection ${ res } ` ) ;
320324 if ( 60000 < Date . now ( ) - start ) {
321325 // reset the retry counter and retry immediately
You can’t perform that action at this time.
0 commit comments