Skip to content

Commit e88b998

Browse files
Fix: connection should not auto retry after DirectLineStreaming.end() (#393)
* fix connectRetry when DirectLineStreaming.end() * add test case * add comment todo --------- Co-authored-by: fangyangci <fangyangci@microsoft.com>
1 parent 8f2b9c8 commit e88b998

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
});

src/directLineStreaming.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)