@@ -5,12 +5,13 @@ const process = require('process');
5
5
const fs = require ( 'fs' ) ;
6
6
const assert = require ( 'assert' ) ;
7
7
8
+ // Based on: https://github.com/nodejs/node/issues/46347#issuecomment-1413886707
8
9
{
9
10
let currentMemoryUsage = process . memoryUsage ( ) . arrayBuffers ;
10
11
11
12
// We initialize a stream, but not start consuming it
12
13
const randomNodeStream = fs . createReadStream ( '/dev/urandom' ) ;
13
- // after 10 seconds, it'll get converted to web stream
14
+ // after 2 seconds, it'll get converted to web stream
14
15
let randomWebStream ;
15
16
16
17
// We check memory usage every second
@@ -23,13 +24,13 @@ const assert = require('assert');
23
24
} ;
24
25
setInterval ( reportMemoryUsage , 1000 ) ;
25
26
26
- // after 10 seconds we use Readable.toWeb
27
+ // after 1 second we use Readable.toWeb
27
28
// memory usage should stay pretty much the same since it's still a stream
28
29
setTimeout ( ( ) => {
29
30
randomWebStream = Readable . toWeb ( randomNodeStream ) ;
30
31
} , 1000 ) ;
31
32
32
- // after 15 seconds we start consuming the stream
33
+ // after 2 seconds we start consuming the stream
33
34
// memory usage will grow, but the old chunks should be garbage-collected pretty quickly
34
35
setTimeout ( async ( ) => {
35
36
// eslint-disable-next-line no-unused-vars
@@ -39,6 +40,7 @@ const assert = require('assert');
39
40
} , 2000 ) ;
40
41
41
42
setTimeout ( ( ) => {
43
+ // Test considered passed if we don't crash
42
44
process . exit ( 0 ) ;
43
45
} , 5000 ) ;
44
46
}
0 commit comments