Skip to content

Commit

Permalink
Revert advanced IPC
Browse files Browse the repository at this point in the history
* Revert "Don't use global setImmediate"

This reverts commit ea66e64.

* Revert "Use advanced serialization (when available) for worker communication"

This reverts commit 0f879f4.
  • Loading branch information
novemberborn committed Aug 24, 2020
1 parent 7694171 commit f499cbf
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 91 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Expand Up @@ -430,7 +430,7 @@ exports.run = async () => { // eslint-disable-line complexity
reporter.startRun(plan);

if (process.env.AVA_EMIT_RUN_STATUS_OVER_IPC === 'I\'ll find a payphone baby / Take some time to talk to you') {
if (process.versions.node >= '12.17.0') {
if (process.versions.node >= '12.16.0') {
plan.status.on('stateChange', evt => {
process.send(evt);
});
Expand Down
20 changes: 6 additions & 14 deletions lib/fork.js
Expand Up @@ -3,7 +3,6 @@ const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const Emittery = require('emittery');
const {controlFlow} = require('./ipc-flow-control');

if (fs.realpathSync(__filename) !== __filename) {
console.warn('WARNING: `npm link ava` and the `--preserve-symlink` flag are incompatible. We have detected that AVA is linked via `npm link`, and that you are using either an early version of Node 6, or the `--preserve-symlink` flag. This breaks AVA. You should upgrade to Node 6.2.0+, avoid the `--preserve-symlink` flag, or avoid using `npm link ava`.');
Expand All @@ -15,12 +14,6 @@ const AVA_PATH = path.resolve(__dirname, '..');

const workerPath = require.resolve('./worker/subprocess');

const useAdvanced = process.versions.node >= '12.17.0';
// FIXME: Fix this in api.js or cli.js.
const serializeOptions = useAdvanced ?
options => JSON.parse(JSON.stringify(options)) : // Use JSON serialization to remove non-clonable values.
options => options;

module.exports = (file, options, execArgv = process.execArgv) => {
let finished = false;

Expand All @@ -41,8 +34,7 @@ module.exports = (file, options, execArgv = process.execArgv) => {
cwd: options.projectDir,
silent: true,
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables, AVA_PATH},
execArgv,
serialization: useAdvanced ? 'advanced' : 'json'
execArgv
});

subprocess.stdout.on('data', chunk => {
Expand All @@ -53,12 +45,12 @@ module.exports = (file, options, execArgv = process.execArgv) => {
emitStateChange({type: 'worker-stderr', chunk});
});

const bufferedSend = controlFlow(subprocess);

let forcedExit = false;
const send = evt => {
if (!finished && !forcedExit) {
bufferedSend({ava: evt});
if (subprocess.connected && !finished && !forcedExit) {
subprocess.send({ava: evt}, () => {
// Disregard errors.
});
}
};

Expand All @@ -74,7 +66,7 @@ module.exports = (file, options, execArgv = process.execArgv) => {
}

if (message.ava.type === 'ready-for-options') {
send({type: 'options', options: serializeOptions(options)});
send({type: 'options', options});
return;
}

Expand Down
42 changes: 0 additions & 42 deletions lib/ipc-flow-control.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/worker/ipc.js
@@ -1,6 +1,5 @@
'use strict';
const Emittery = require('emittery');
const {controlFlow} = require('../ipc-flow-control');

const emitter = new Emittery();
process.on('message', message => {
Expand All @@ -26,9 +25,10 @@ process.on('message', message => {
exports.options = emitter.once('options');
exports.peerFailed = emitter.once('peerFailed');

const bufferedSend = controlFlow(process);
function send(evt) {
bufferedSend({ava: evt});
if (process.connected) {
process.send({ava: evt});
}
}

exports.send = send;
Expand Down
2 changes: 1 addition & 1 deletion test-tap/fixture/report/regular/uncaught-exception.js
@@ -1,7 +1,7 @@
const test = require('../../../..');

test('passes', t => {
setImmediate(() => {
setTimeout(() => {
throw new Error('Can’t catch me');
});
t.pass();
Expand Down
4 changes: 2 additions & 2 deletions test-tap/reporters/mini.regular.v10.log
Expand Up @@ -515,13 +515,13 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.setImmediate (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› Timeout.setTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)



Expand Down
7 changes: 4 additions & 3 deletions test-tap/reporters/mini.regular.v12.log
Expand Up @@ -497,14 +497,15 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.<anonymous> (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› processImmediate (internal/timers.js:456:21)
› Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› listOnTimeout (internal/timers.js:549:17)
› processTimers (internal/timers.js:492:7)



Expand Down
7 changes: 4 additions & 3 deletions test-tap/reporters/mini.regular.v14.log
Expand Up @@ -497,14 +497,15 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.<anonymous> (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› processImmediate (internal/timers.js:458:21)
› Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› listOnTimeout (internal/timers.js:551:17)
› processTimers (internal/timers.js:494:7)



Expand Down
4 changes: 1 addition & 3 deletions test-tap/reporters/tap.regular.v10.log
Expand Up @@ -323,9 +323,7 @@ not ok 25 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: >-
Immediate.setImmediate
(test-tap/fixture/report/regular/uncaught-exception.js:5:9)
at: 'Timeout.setTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)'
...
---tty-stream-chunk-separator
# uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
9 changes: 4 additions & 5 deletions test-tap/reporters/tap.regular.v12.log
Expand Up @@ -296,11 +296,10 @@ not ok 25 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: >-
Immediate.<anonymous>
(test-tap/fixture/report/regular/uncaught-exception.js:5:9)

processImmediate (internal/timers.js:456:21)
at: |-
Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
listOnTimeout (internal/timers.js:549:17)
processTimers (internal/timers.js:492:7)
...
---tty-stream-chunk-separator
# uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
9 changes: 4 additions & 5 deletions test-tap/reporters/tap.regular.v14.log
Expand Up @@ -296,11 +296,10 @@ not ok 25 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: >-
Immediate.<anonymous>
(test-tap/fixture/report/regular/uncaught-exception.js:5:9)

processImmediate (internal/timers.js:458:21)
at: |-
Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
listOnTimeout (internal/timers.js:551:17)
processTimers (internal/timers.js:494:7)
...
---tty-stream-chunk-separator
# uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
4 changes: 2 additions & 2 deletions test-tap/reporters/verbose.regular.v10.log
Expand Up @@ -87,13 +87,13 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.setImmediate (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› Timeout.setTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)

---tty-stream-chunk-separator
✖ uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
7 changes: 4 additions & 3 deletions test-tap/reporters/verbose.regular.v12.log
Expand Up @@ -87,14 +87,15 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.<anonymous> (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› processImmediate (internal/timers.js:456:21)
› Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› listOnTimeout (internal/timers.js:549:17)
› processTimers (internal/timers.js:492:7)

---tty-stream-chunk-separator
✖ uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
7 changes: 4 additions & 3 deletions test-tap/reporters/verbose.regular.v14.log
Expand Up @@ -87,14 +87,15 @@

uncaught-exception.js:5

4: setImmediate(() => {
4: setTimeout(() => {
 5: throw new Error('Can’t catch me');
6: });

Error: Can’t catch me

› Immediate.<anonymous> (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› processImmediate (internal/timers.js:458:21)
› Timeout._onTimeout (test-tap/fixture/report/regular/uncaught-exception.js:5:9)
› listOnTimeout (internal/timers.js:551:17)
› processTimers (internal/timers.js:494:7)

---tty-stream-chunk-separator
✖ uncaught-exception.js exited with a non-zero exit code: 1
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/exec.js
Expand Up @@ -8,7 +8,7 @@ const defaultsDeep = require('lodash/defaultsDeep');
const cliPath = path.resolve(__dirname, '../../cli.js');
const ttySimulator = path.join(__dirname, './simulate-tty.js');

const serialization = process.versions.node >= '12.17.0' ? 'advanced' : 'json';
const serialization = process.versions.node >= '12.16.0' ? 'advanced' : 'json';

const normalizePath = (root, file) => path.posix.normalize(path.relative(root, file));

Expand Down

0 comments on commit f499cbf

Please sign in to comment.