-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trace_events: trace net connect event
PR-URL: #43903 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
const CODE = ` | ||
const net = require('net'); | ||
const socket = net.connect('${common.PIPE}'); | ||
socket.on('error', () => {}); | ||
const server = net.createServer((socket) => { | ||
socket.destroy(); | ||
server.close(); | ||
}).listen(0, () => { | ||
net.connect(server.address().port); | ||
}); | ||
`; | ||
|
||
tmpdir.refresh(); | ||
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log'); | ||
|
||
const proc = cp.spawn(process.execPath, | ||
[ '--trace-events-enabled', | ||
'--trace-event-categories', 'node.net.native', | ||
'-e', CODE ], | ||
{ cwd: tmpdir.path }); | ||
|
||
proc.once('exit', common.mustCall(() => { | ||
assert(fs.existsSync(FILE_NAME)); | ||
fs.readFile(FILE_NAME, common.mustCall((err, data) => { | ||
const traces = JSON.parse(data.toString()).traceEvents; | ||
assert(traces.length > 0); | ||
let count = 0; | ||
traces.forEach((trace) => { | ||
if (trace.cat === 'node,node.net,node.net.native' && | ||
trace.name === 'connect') { | ||
count++; | ||
} | ||
}); | ||
// Two begin, two end | ||
assert.strictEqual(count, 4); | ||
})); | ||
})); |