MCPcopy
hub / github.com/alibaba/anyproxy / testWebsocket

Function testWebsocket

test/spec_rule/no_rule_websocket_spec.js:16–128  ·  view source on GitHub ↗
(protocol, masked = false)

Source from the content-addressed store, hash-verified

14testWebsocket('wss', true);
15
16function testWebsocket(protocol, masked = false) {
17 describe('Test WebSocket in protocol : ' + protocol, () => {
18 const url = generateWsUrl(protocol, '/test/socket');
19 let serverInstance;
20 let proxyServer;
21 // the message to
22 const testMessageArray = [
23 'Send the message with default option1',
24 'Send the message with default option2',
25 'Send the message with default option3',
26 'Send the message with default option4'
27 ];
28
29 beforeAll((done) => {
30 jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000;
31 printLog('Start server for no_rule_websocket_spec');
32 serverInstance = new Server();
33
34 proxyServer = ProxyServerUtil.defaultProxyServer();
35
36 setTimeout(() => {
37 done();
38 }, 2000);
39 });
40
41 afterAll(() => {
42 serverInstance && serverInstance.close();
43 proxyServer && proxyServer.close();
44 printLog('Closed server for no_rule_websocket_spec');
45 });
46
47 it('Default websocket option', done => {
48 const directMessages = []; // set the flag for direct message, compare when both direct and proxy got message
49 const proxyMessages = [];
50 let directHeaders;
51 let proxyHeaders;
52
53 const ws = directWs(url);
54 const proxyWsRef = proxyWs(url);
55 ws.on('open', () => {
56 ws.send(testMessageArray[0], masked);
57 for (let i = 1; i < testMessageArray.length; i++) {
58 setTimeout(() => {
59 ws.send(testMessageArray[i], masked);
60 }, 1000);
61 }
62 });
63
64 proxyWsRef.on('open', () => {
65 try {
66 proxyWsRef.send(testMessageArray[0], masked);
67 for (let i = 1; i < testMessageArray.length; i++) {
68 setTimeout(() => {
69 proxyWsRef.send(testMessageArray[i], masked);
70 }, 1000);
71 }
72 } catch (e) {
73 console.error(e);

Callers 1

Calls 6

generateWsUrlFunction · 0.85
directWsFunction · 0.85
proxyWsFunction · 0.85
compareMessageIfReadyFunction · 0.85
printLogFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected