-
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.
Add trace points to dns under node.dns.native category. Emit trace events for dns operations. Use the nestable async events instead of deprecated ones. Include test code to verify the trace log. The trace name is stored as const char* class variable. The test code is to check each operation in separate sync processes. Refs: #19157 PR-URL: #21840 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
- Loading branch information
1 parent
6d6db60
commit c52d67b
Showing
2 changed files
with
125 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fs = require('fs'); | ||
const util = require('util'); | ||
|
||
if (!common.isMainThread) | ||
common.skip('process.chdir is not available in Workers'); | ||
|
||
const traceFile = 'node_trace.1.log'; | ||
|
||
tmpdir.refresh(); | ||
process.chdir(tmpdir.path); | ||
|
||
const test_str = 'const dns = require("dns");' + | ||
'const options = {' + | ||
' family: 4,' + | ||
' hints: dns.ADDRCONFIG | dns.V4MAPPED,' + | ||
'};'; | ||
|
||
const tests = { | ||
'lookup': 'dns.lookup("example.com", options, (err, address, family) => {});', | ||
'lookupService': 'dns.lookupService("127.0.0.1", 22, ' + | ||
'(err, hostname, service) => {});', | ||
'reverse': 'dns.reverse("8.8.8.8", (err, hostnames) => {});', | ||
'resolveAny': 'dns.resolveAny("example.com", (err, res) => {});', | ||
'resolve4': 'dns.resolve4("example.com", (err, res) => {});', | ||
'resolve6': 'dns.resolve6("example.com", (err, res) => {});', | ||
'resolveCname': 'dns.resolveCname("example.com", (err, res) => {});', | ||
'resolveMx': 'dns.resolveMx("example.com", (err, res) => {});', | ||
'resolveNs': 'dns.resolveNs("example.com", (err, res) => {});', | ||
'resolveTxt': 'dns.resolveTxt("example.com", (err, res) => {});', | ||
'resolveSrv': 'dns.resolveSrv("example.com", (err, res) => {});', | ||
'resolvePtr': 'dns.resolvePtr("example.com", (err, res) => {});', | ||
'resolveNaptr': 'dns.resolveNaptr("example.com", (err, res) => {});', | ||
'resolveSoa': 'dns.resolveSoa("example.com", (err, res) => {});' | ||
}; | ||
|
||
for (const tr in tests) { | ||
const proc = cp.spawnSync(process.execPath, | ||
[ '--trace-event-categories', | ||
'node.dns.native', | ||
'-e', | ||
test_str + tests[tr] | ||
], | ||
{ encoding: 'utf8' }); | ||
|
||
// Make sure the operation is successful. | ||
assert.strictEqual(proc.status, 0, `${tr}:\n${util.inspect(proc)}`); | ||
|
||
const file = path.join(tmpdir.path, traceFile); | ||
|
||
// Confirm that trace log file is created. | ||
assert(common.fileExists(file)); | ||
const data = fs.readFileSync(file); | ||
const traces = JSON.parse(data.toString()).traceEvents | ||
.filter((trace) => trace.cat !== '__metadata'); | ||
|
||
assert(traces.length > 0); | ||
|
||
// DNS native trace events should be generated. | ||
assert(traces.some((trace) => { | ||
return (trace.name === tr && trace.pid === proc.pid); | ||
})); | ||
} |