-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
63 lines (47 loc) · 1.5 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const {deepStrictEqual} = require('node:assert/strict')
const EventEmitter = require('node:events')
const test = require('node:test')
const getStatsFactory = require('./index.js')
test('lifecycle', async function()
{
const mediasoup = {
async createWorker()
{
const worker = {
close()
{
this.observer.emit('close')
},
async getResourceUsage()
{
return {}
},
observer: new EventEmitter,
pid: process.pid
}
this.observer.emit('newworker', worker)
return worker
},
observer: new EventEmitter
}
const {close, getStats} = await getStatsFactory(mediasoup)
deepStrictEqual(typeof close, 'function')
deepStrictEqual(typeof getStats, 'function')
const stats1 = await getStats()
deepStrictEqual(typeof stats1, 'object')
deepStrictEqual(typeof stats1.os, 'object')
deepStrictEqual(typeof stats1.pidusages, 'undefined')
deepStrictEqual(typeof stats1.process, 'object')
const worker = await mediasoup.createWorker()
deepStrictEqual(typeof worker, 'object')
deepStrictEqual(typeof worker.getResourceUsage, 'function')
const resourceUsage = await worker.getResourceUsage()
deepStrictEqual(typeof resourceUsage, 'object')
const stats2 = await getStats()
deepStrictEqual(typeof stats2, 'object')
deepStrictEqual(typeof stats2.os, 'object')
deepStrictEqual(typeof stats2.pidusages, 'object')
deepStrictEqual(typeof stats2.process, 'object')
worker.close()
close()
})