test/specs/drops.ts   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 29
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 25
mnd 3
bc 3
fnc 0
dl 0
loc 29
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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
}))