summaryrefslogtreecommitdiff
path: root/test/parallel/test-sync-io-option.js
blob: 3dfe622963a0e249c3d27defb22a30483473093f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';

require('../common');
const assert = require('assert');
const execFile = require('child_process').execFile;

if (process.argv[2] === 'child') {
  setImmediate(function() {
    require('fs').readFileSync(__filename);
    process.exit();
  });

} else {
  (function runTest(flags) {
    const execArgv = [flags.pop()];
    let args = [__filename, 'child'];
    let cntr = 0;
    args = execArgv.concat(args);
    if (!args[0]) args.shift();
    execFile(process.execPath, args, function(err, stdout, stderr) {
      assert.strictEqual(err, null);
      assert.strictEqual(stdout, '');
      if (/WARNING[\s\S]*readFileSync/.test(stderr))
        cntr++;
      if (args[0] === '--trace-sync-io') {
        assert.strictEqual(cntr, 1);
      } else if (args[0] === __filename) {
        assert.strictEqual(cntr, 0);
      } else {
        throw new Error('UNREACHABLE');
      }
      if (flags.length > 0)
        setImmediate(runTest, flags);
    });
  }(['--trace-sync-io', '']));
}