| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e138fe commit deef2f6
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cp = require('child_process'); | ||
| 5 | + | ||
| 6 | + if (process.argv[2] === 'child') { | ||
| 7 | + setTimeout(() => { | ||
| 8 | + // The following console statements are part of the test. | ||
| 9 | + console.log('child stdout'); | ||
| 10 | + console.error('child stderr'); | ||
| 11 | + }, common.platformTimeout(1000)); | ||
| 12 | + return; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + const cmd = `${process.execPath} ${__filename} child`; | ||
| 16 | + | ||
| 17 | + // Test the case where a timeout is set, and it expires. | ||
| 18 | + cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { | ||
| 19 | + assert.strictEqual(err.killed, true); | ||
| 20 | + assert.strictEqual(err.code, null); | ||
| 21 | + assert.strictEqual(err.signal, 'SIGTERM'); | ||
| 22 | + assert.strictEqual(err.cmd, cmd); | ||
| 23 | + assert.strictEqual(stdout.trim(), ''); | ||
| 24 | + assert.strictEqual(stderr.trim(), ''); | ||
| 25 | + })); | ||
| 26 | + | ||
| 27 | + // Test with a different kill signal. | ||
| 28 | + cp.exec(cmd, { | ||
| 29 | + timeout: 1, | ||
| 30 | + killSignal: 'SIGKILL' | ||
| 31 | + }, common.mustCall((err, stdout, stderr) => { | ||
| 32 | + assert.strictEqual(err.killed, true); | ||
| 33 | + assert.strictEqual(err.code, null); | ||
| 34 | + assert.strictEqual(err.signal, 'SIGKILL'); | ||
| 35 | + assert.strictEqual(err.cmd, cmd); | ||
| 36 | + assert.strictEqual(stdout.trim(), ''); | ||
| 37 | + assert.strictEqual(stderr.trim(), ''); | ||
| 38 | + })); | ||
| 39 | + | ||
| 40 | + // Test the case where a timeout is set, but not expired. | ||
| 41 | + cp.exec(cmd, { timeout: 2 ** 30 }, common.mustCall((err, stdout, stderr) => { | ||
| 42 | + assert.ifError(err); | ||
| 43 | + assert.strictEqual(stdout.trim(), 'child stdout'); | ||
| 44 | + assert.strictEqual(stderr.trim(), 'child stderr'); | ||
| 45 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments