Total Complexity | 3 |
Complexity/F | 0 |
Lines of Code | 30 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { createNew } from '../utils' |
||
2 | import mockServer from '../mock/server' |
||
3 | import { test } from '../suite' |
||
4 | |||
5 | /** Rejects messages by timout */ |
||
6 | test('drops', () => new Promise(async (ff, rj) => { |
||
7 | const {port, shutDown} = await mockServer() |
||
8 | const ws = createNew({timeout: 500}, port) |
||
9 | |||
10 | await shutDown() |
||
11 | const lauchServ = async () => await mockServer(port) |
||
12 | |||
13 | setTimeout(async () => { |
||
14 | const msg = {echo: true, msg: 'hello!'} |
||
15 | let to: NodeJS.Timeout |
||
16 | try { |
||
17 | to = setTimeout(() => { |
||
18 | return rj() |
||
19 | }, 600) |
||
20 | await ws.send(msg) |
||
21 | if(to) clearTimeout(to) |
||
22 | await lauchServ() |
||
23 | return rj() |
||
24 | } catch(e) { |
||
25 | if(to!) clearTimeout(to) |
||
26 | await lauchServ() |
||
27 | return ff() |
||
28 | } |
||
29 | }, 200) |
||
30 | })) |