diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-14 01:22:17 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-20 16:55:29 +0100 |
commit | cfcbfc001150e088b489b1fb3de50d516f4e3c65 (patch) | |
tree | 3122ab0d826b8167dbc49a5624c3561d699482de /test/parallel/test-inspector-heap-allocation-tracker.js | |
parent | a34a84d281a53e87b6a62c40fc6491a1e0f3c96b (diff) | |
download | android-node-v8-cfcbfc001150e088b489b1fb3de50d516f4e3c65.tar.gz android-node-v8-cfcbfc001150e088b489b1fb3de50d516f4e3c65.tar.bz2 android-node-v8-cfcbfc001150e088b489b1fb3de50d516f4e3c65.zip |
test,inspector: add heap allocation tracker test
This provides coverage for the `InspectorTimer` instances
created as part of heap allocation tracking.
PR-URL: https://github.com/nodejs/node/pull/26089
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-inspector-heap-allocation-tracker.js')
-rw-r--r-- | test/parallel/test-inspector-heap-allocation-tracker.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/parallel/test-inspector-heap-allocation-tracker.js b/test/parallel/test-inspector-heap-allocation-tracker.js new file mode 100644 index 0000000000..0003a8fb69 --- /dev/null +++ b/test/parallel/test-inspector-heap-allocation-tracker.js @@ -0,0 +1,46 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const inspector = require('inspector'); +const stream = require('stream'); +const { Worker, workerData } = require('worker_threads'); + +const session = new inspector.Session(); +session.connect(); +session.post('HeapProfiler.enable'); +session.post('HeapProfiler.startTrackingHeapObjects', + { trackAllocations: true }); + +// Perform some silly heap allocations for the next 100 ms. +const interval = setInterval(() => { + new stream.PassThrough().end('abc').on('data', common.mustCall()); +}, 1); + +setTimeout(() => { + clearInterval(interval); + + // Once the main test is done, we re-run it from inside a Worker thread + // and stop early, as that is a good way to make sure the timer handles + // internally created by the inspector are cleaned up properly. + if (workerData === 'stopEarly') + process.exit(); + + let data = ''; + session.on('HeapProfiler.addHeapSnapshotChunk', + common.mustCallAtLeast((event) => { + data += event.params.chunk; + })); + + // TODO(addaleax): Using `{ reportProgress: true }` crashes the process + // because the progress indication event would mean calling into JS while + // a heap snapshot is being taken, which is forbidden. + // What can we do about that? + session.post('HeapProfiler.stopTrackingHeapObjects'); + + assert(data.includes('PassThrough'), data); + + new Worker(__filename, { workerData: 'stopEarly' }); +}, 100); |