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

Function test

test/parallel/test-pipe-stream.js:9–59  ·  view source on GitHub ↗
(clazz, cb)

Source from the content-addressed store, hash-verified

7tmpdir.refresh();
8
9function test(clazz, cb) {
10 let have_ping = false;
11 let have_pong = false;
12
13 function check() {
14 assert.ok(have_ping);
15 assert.ok(have_pong);
16 }
17
18 function ping() {
19 const conn = new clazz();
20
21 conn.on('error', function(err) {
22 throw err;
23 });
24
25 conn.connect(common.PIPE, function() {
26 conn.write('PING', 'utf-8');
27 });
28
29 conn.on('data', common.mustCallAtLeast((data) => {
30 assert.strictEqual(data.toString(), 'PONG');
31 have_pong = true;
32 conn.destroy();
33 }));
34 }
35
36 function pong(conn) {
37 conn.on('error', function(err) {
38 throw err;
39 });
40
41 conn.on('data', common.mustCall((data) => {
42 assert.strictEqual(data.toString(), 'PING');
43 have_ping = true;
44 conn.write('PONG', 'utf-8');
45 }));
46
47 conn.on('close', function() {
48 server.close();
49 });
50 }
51
52 const server = net.Server();
53 server.listen(common.PIPE, ping);
54 server.on('connection', pong);
55 server.on('close', function() {
56 check();
57 cb && cb();
58 });
59}
60
61test(net.Stream, function() {
62 test(net.Socket);

Callers 1

Calls 4

listenMethod · 0.80
checkFunction · 0.70
cbFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…