Skip to content

Commit

Permalink
stream: change comment
Browse files Browse the repository at this point in the history
  • Loading branch information
CGQAQ committed Jul 20, 2023
1 parent 2434906 commit a87605f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/parallel/test-stream-readable-to-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const process = require('process');
const fs = require('fs');
const assert = require('assert');

// Based on: https:/nodejs/node/issues/46347#issuecomment-1413886707
{
let currentMemoryUsage = process.memoryUsage().arrayBuffers;

// We initialize a stream, but not start consuming it
const randomNodeStream = fs.createReadStream('/dev/urandom');
// after 10 seconds, it'll get converted to web stream
// after 2 seconds, it'll get converted to web stream
let randomWebStream;

// We check memory usage every second
Expand All @@ -23,13 +24,13 @@ const assert = require('assert');
};
setInterval(reportMemoryUsage, 1000);

// after 10 seconds we use Readable.toWeb
// after 1 second we use Readable.toWeb
// memory usage should stay pretty much the same since it's still a stream
setTimeout(() => {
randomWebStream = Readable.toWeb(randomNodeStream);
}, 1000);

// after 15 seconds we start consuming the stream
// after 2 seconds we start consuming the stream
// memory usage will grow, but the old chunks should be garbage-collected pretty quickly
setTimeout(async () => {
// eslint-disable-next-line no-unused-vars
Expand All @@ -39,6 +40,7 @@ const assert = require('assert');
}, 2000);

setTimeout(() => {
// Test considered passed if we don't crash
process.exit(0);
}, 5000);
}

0 comments on commit a87605f

Please sign in to comment.