• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Flags: --expose-gc
3
4// Note: This is a variant of test-net-write-fully-async-hex-string.js.
5// This always worked, but it seemed appropriate to add a test that checks the
6// behavior for Buffers, too.
7const common = require('../common');
8const net = require('net');
9
10const data = Buffer.alloc(1000000);
11
12const server = net.createServer(common.mustCall(function(conn) {
13  conn.resume();
14})).listen(0, common.mustCall(function() {
15  const conn = net.createConnection(this.address().port, common.mustCall(() => {
16    let count = 0;
17
18    function writeLoop() {
19      if (count++ === 200) {
20        conn.destroy();
21        server.close();
22        return;
23      }
24
25      while (conn.write(Buffer.from(data)));
26      global.gc(true);
27      // The buffer allocated above should still be alive.
28    }
29
30    conn.on('drain', writeLoop);
31
32    writeLoop();
33  }));
34}));
35