Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow responses over 1MB in node 12 #8

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ language: node_js
sudo: false

node_js:
- "8"
- '8'
- '10'
- '12'

script: npm test && npm run prettier:check

Expand Down
36 changes: 34 additions & 2 deletions lib/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test('it should work', () => {
}
});

let nativeNCFails = false;

rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
test('profile ' + fn.name, () => {
try {
Expand All @@ -18,10 +20,36 @@ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
const end = Date.now();
console.log(fn.name + ': ' + (end - start));
} catch (ex) {
console.log(fn.name + ' fails');
if (fn.name === 'nativeNC') {
console.log(fn.name + ' fails');
nativeNCFails = true;
return;
}
throw ex;
}
});
});

rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
test('test 30MB ' + fn.name, () => {
let result;
try {
rpc.configuration.fastestFunction = fn;
result = client('big');
} catch (ex) {
if (fn.name === 'nativeNC' && nativeNCFails) {
console.log(fn.name + ' fails');
return;
}
throw ex;
}
expect(result.length).toBe(30 * 1024 * 1024, 42);
// for (let i = 0; i < 30 * 1024 * 1024, 42; i++) {
// expect(result[i]).toBe(42);
// }
});
});

rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
let longMessage = '';
for (let i = 0; i < 100000; i++) {
Expand All @@ -37,7 +65,11 @@ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
const end = Date.now();
console.log('large ' + fn.name + ': ' + (end - start));
} catch (ex) {
console.log('large ' + fn.name + ' fails');
if (fn.name === 'nativeNC' && nativeNCFails) {
console.log('large ' + fn.name + ' fails');
return;
}
throw ex;
}
});
});
17 changes: 14 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,26 @@ function waitForAlive(port) {
}

function nativeNC(port, input) {
return spawnSync('nc', [host, port], {input: input, windowsHide: true});
return spawnSync('nc', [host, port], {
input: input,
windowsHide: true,
maxBuffer: Infinity,
});
}

function nodeNC(port, input) {
const src = nodeNetCatSrc(port, input);
if (src.length < 1000) {
return spawnSync(process.execPath, ['-e', src], {windowsHide: true});
return spawnSync(process.execPath, ['-e', src], {
windowsHide: true,
maxBuffer: Infinity,
});
} else {
return spawnSync(process.execPath, [], {input: src, windowsHide: true});
return spawnSync(process.execPath, [], {
input: src,
windowsHide: true,
maxBuffer: Infinity,
});
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/test-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function init(connection) {
return function(message) {
if (message === 'big') {
return Promise.resolve(Buffer.alloc(30 * 1024 * 1024, 42));
}
return Promise.resolve('sent ' + message + ' to ' + connection);
};
}
Expand Down