MCPcopy Index your code
hub / github.com/nodejs/node / runTests

Function runTests

test/parallel/test-fastutf8stream-periodicflush.js:27–78  ·  view source on GitHub ↗
(sync)

Source from the content-addressed store, hash-verified

25runTests(true);
26
27function runTests(sync) {
28
29 {
30 const dest = getTempFile();
31 const fd = openSync(dest, 'w');
32 const stream = new Utf8Stream({ fd, sync, minLength: 5000 });
33
34 assert.ok(stream.write('hello world\n'));
35
36 setTimeout(common.mustCall(() => {
37 readFile(dest, 'utf8', common.mustSucceed((data) => {
38 assert.strictEqual(data, '');
39 }));
40 }), 1500);
41
42 stream.destroy();
43 }
44
45 {
46 const dest = getTempFile();
47 const fd = openSync(dest, 'w');
48
49 // Test that periodicFlush property is set correctly
50 const stream1 = new Utf8Stream({ fd, sync, minLength: 5000 });
51 assert.strictEqual(stream1.periodicFlush, 0);
52 stream1.destroy();
53
54 const fd2 = openSync(dest, 'w');
55 const stream2 = new Utf8Stream({ fd: fd2, sync, minLength: 5000, periodicFlush: 1000 });
56 assert.strictEqual(stream2.periodicFlush, 1000);
57 stream2.destroy();
58 }
59
60 {
61 const dest = getTempFile();
62 const fd = openSync(dest, 'w');
63 const stream = new Utf8Stream({ fd, sync, minLength: 5000 });
64
65 assert.ok(stream.write('hello world\n'));
66
67 // Manually flush to test that data can be written
68 stream.flush(common.mustSucceed());
69
70 setTimeout(common.mustCall(() => {
71 readFile(dest, 'utf8', common.mustSucceed((data) => {
72 assert.strictEqual(data, 'hello world\n');
73 }));
74 }), 500);
75
76 stream.destroy();
77 }
78}

Calls 8

writeMethod · 0.95
destroyMethod · 0.95
flushMethod · 0.95
getTempFileFunction · 0.70
openSyncFunction · 0.70
readFileFunction · 0.70
setTimeoutFunction · 0.50
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…