mirror of
https://github.com/denoland/deno.git
synced 2024-12-14 03:23:17 -05:00
6915a9b7a7
This PR adds the remaining ~650 Node.js compat test cases from std/node. Among these 650 cases, about 130 cases are now failing. These failing cases are prefixed with `TODO:` in `tests/node_compat/config.json`. These will be addressed in later PRs.
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
// deno-fmt-ignore-file
|
|
// deno-lint-ignore-file
|
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
// Taken from Node 16.13.0
|
|
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
|
|
|
// Flags: --expose-gc
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (process.config.variables.asan) {
|
|
common.skip('ASAN messes with memory measurements');
|
|
}
|
|
|
|
if (process.config.variables.arm_version === '7') {
|
|
common.skip('Too slow for armv7 bots');
|
|
}
|
|
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
// Tests that, when receiving small chunks, we do not keep the full length
|
|
// of the original allocation for the libuv read call in memory.
|
|
|
|
let client;
|
|
let baseRSS;
|
|
const receivedChunks = [];
|
|
const N = 250000;
|
|
|
|
const server = net.createServer(common.mustCall((socket) => {
|
|
baseRSS = process.memoryUsage.rss();
|
|
|
|
socket.setNoDelay(true);
|
|
socket.on('data', (chunk) => {
|
|
receivedChunks.push(chunk);
|
|
if (receivedChunks.length < N) {
|
|
client.write('a');
|
|
} else {
|
|
client.end();
|
|
server.close();
|
|
}
|
|
});
|
|
})).listen(0, common.mustCall(() => {
|
|
client = net.connect(server.address().port);
|
|
client.setNoDelay(true);
|
|
client.write('hello!');
|
|
}));
|
|
|
|
process.on('exit', () => {
|
|
// TODO: support global.gc() compat
|
|
// global.gc();
|
|
const bytesPerChunk =
|
|
(process.memoryUsage.rss() - baseRSS) / receivedChunks.length;
|
|
// We should always have less than one page (usually ~ 4 kB) per chunk.
|
|
assert(bytesPerChunk < 650, `measured ${bytesPerChunk} bytes per chunk`);
|
|
});
|