-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathhappy.dlstreamConnection.js
More file actions
60 lines (52 loc) · 2.18 KB
/
happy.dlstreamConnection.js
File metadata and controls
60 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'dotenv/config';
import onErrorResumeNext from 'on-error-resume-next';
import { timeouts } from './constants.json';
import * as createDirectLine from './setup/createDirectLine';
import waitForConnected from './setup/waitForConnected';
import { async } from 'rxjs/scheduler/async';
import {
ConnectionStatus
} from '../src/directLine.ts';
// TODO: Need more realistic testing.
// - Able to connect to a Web Socket server
// - Make sure after `end` is called, the client will not reconnect
// - If the connection is disrupted, make sure the client will reconnect
// - Use a fake timer to speed up the test
describe('test dl streaming end', () => {
let unsubscribes;
let directLineStreaming;
beforeEach(() => unsubscribes = []);
afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn)));
test('using Streaming Extensions', async () => {
directLineStreaming = await createDirectLine.forStreamingExtensions();
unsubscribes.push(directLineStreaming.end.bind(directLineStreaming));
unsubscribes.push(await waitForConnected(directLineStreaming));
directLineStreaming.end();
expect(directLineStreaming.connectionStatus$.getValue()).toBe(ConnectionStatus.Ended);
})
});
describe('test dl streaming reconnect', () => {
let unsubscribes;
let directLineStreaming;
beforeEach(() => unsubscribes = []);
afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn)));
test('using Streaming Extensions', async () => {
let errorTimes = 2;
directLineStreaming = await createDirectLine.forStreamingExtensions();
let tmpConnect = directLineStreaming.connectAsync;
directLineStreaming.connectAsync = async function () {
errorTimes--;
console.log(`connectAsync errorTimes:${errorTimes}`);
if (errorTimes >= 0){
throw new Error("TestErr");
}
tmpConnect.call(directLineStreaming);
}
directLineStreaming.getRetryDelay = function () {
return 0;
}
unsubscribes.push(directLineStreaming.end.bind(directLineStreaming));
unsubscribes.push(await waitForConnected(directLineStreaming));
expect(directLineStreaming.connectionStatus$.getValue()).toBe(ConnectionStatus.Online);
})
});