Passed
Branch master (5df6c0)
by Michael
02:01
created

test/specs/drops.ts   A

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 30
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 30
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
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
}))