forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-performance-uvmetricsinfo.js
More file actions
74 lines (60 loc) · 1.7 KB
/
test-performance-uvmetricsinfo.js
File metadata and controls
74 lines (60 loc) · 1.7 KB
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
64
65
66
67
68
69
70
71
72
73
74
'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const filepath = fixtures.path('x.txt');
const assert = require('node:assert');
const fs = require('node:fs');
const { performance } = require('node:perf_hooks');
const { uvMetricsInfo } = performance;
function safeMetricsInfo(cb) {
setImmediate(() => {
const info = uvMetricsInfo();
cb(info);
});
}
{
const info = uvMetricsInfo();
assert.strictEqual(info.loopCount, 0);
assert.strictEqual(info.events, 0);
// This is the only part of the test that we test events waiting
// Adding checks for this property will make the test flaky
// as it can be highly influenced by race conditions.
assert.strictEqual(info.eventsWaiting, 0);
}
{
// The synchronous call should obviously not affect the uv metrics
const fd = fs.openSync(filepath, 'r');
fs.readFileSync(fd);
const info = uvMetricsInfo();
assert.strictEqual(info.loopCount, 0);
assert.strictEqual(info.events, 0);
assert.strictEqual(info.eventsWaiting, 0);
}
{
function openFile(info) {
assert.strictEqual(info.loopCount, 1);
// 1. ? event
assert.strictEqual(info.events, 1);
fs.open(filepath, 'r', (err) => {
assert.ifError(err);
safeMetricsInfo(afterOpenFile);
});
}
function afterOpenFile(info) {
assert.strictEqual(info.loopCount, 2);
// 1. ? event
// 2. uv_fs_open
assert.strictEqual(info.events, 2);
fs.readFile(filepath, (err) => {
assert.ifError(err);
safeMetricsInfo(afterReadFile);
});
}
function afterReadFile(info) {
assert.strictEqual(info.loopCount, 6);
// 1. ? event
assert.strictEqual(info.events, 6);
// 1. ?
}
safeMetricsInfo(openFile);
}