Total Complexity | 3 |
Complexity/F | 0 |
Lines of Code | 29 |
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 | import { wait } from 'pepka' |
||
5 | |||
6 | /** Rejects messages by timout */ |
||
7 | test('drops', () => new Promise(async (ff, rj) => { |
||
8 | const {port, shutDown} = await mockServer() |
||
9 | const ws = createNew({timeout: 500}, port) |
||
10 | |||
11 | await shutDown() |
||
12 | await wait(200) |
||
13 | |||
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 mockServer(port) |
||
23 | return rj() |
||
24 | } catch(e) { |
||
25 | if(to!) clearTimeout(to) |
||
26 | await mockServer(port) |
||
27 | return ff() |
||
28 | } |
||
29 | })) |