-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
2 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
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,72 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
if (process.env.isChild === '1') { | ||
const { open, opendir } = require('fs/promises'); | ||
const trace_events = require('trace_events'); | ||
const tracing = trace_events.createTracing({ categories: ['node.fs.async', 'node.fs.sync', 'node.fs_dir.sync'] }); | ||
tracing.enable(); | ||
(async function test() { | ||
// Call FileHandle::Close(const FunctionCallbackInfo<Value>& args) | ||
{ | ||
let filehandle = null; | ||
try { | ||
filehandle = await open(__filename, 'r'); | ||
} finally { | ||
await filehandle.close(); | ||
} | ||
} | ||
// Call void FileHandle::Close() during gc | ||
{ | ||
let filehandle = null; | ||
try { | ||
filehandle = await open(__filename, 'r'); | ||
} finally { | ||
filehandle = null; | ||
} | ||
} | ||
// Call void DirHandle::GCClose() during gc | ||
{ | ||
let dir = await opendir('.'); | ||
dir = null; | ||
} | ||
gc(); | ||
})(); | ||
return; | ||
} | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
const traceFile = path.join(tmpdir.path, 'node_trace.1.log'); | ||
|
||
cp.spawnSync(process.execPath, | ||
['--expose-gc', __filename], | ||
{ cwd: tmpdir.path, encoding: 'utf8', env: { ...process.env, isChild: '1' } }); | ||
|
||
assert(fs.existsSync(traceFile)); | ||
const data = fs.readFileSync(traceFile); | ||
const traces = JSON.parse(data.toString()).traceEvents; | ||
assert(traces.length > 0); | ||
|
||
let syncClose = 0; | ||
let asyncClose = 0; | ||
let syncCloseDir = 0; | ||
|
||
traces.forEach((trace) => { | ||
if (trace.cat === 'node,node.fs,node.fs.sync' && trace.name === 'fs.sync.close') { | ||
syncClose++; | ||
} else if (trace.cat === 'node,node.fs,node.fs.async' && trace.name === 'close') { | ||
asyncClose++; | ||
} else if (trace.cat === 'node,node.fs_dir,node.fs_dir.sync' && trace.name === 'fs_dir.sync.closedir') { | ||
syncCloseDir++; | ||
} | ||
}); | ||
|
||
// One begin event, one end event | ||
assert.strictEqual(syncClose, 2); | ||
assert.strictEqual(asyncClose, 2); | ||
assert.strictEqual(syncCloseDir, 2); |