From 9cdc6b67412134e9d226d18cdb41cb4aba0e348b Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Thu, 5 Mar 2020 09:28:31 -0500 Subject: [PATCH 1/4] test: use portable EOL The test wanted to cut huge string into 1KB strings, for which a new line character was inserted at appropriate places. The value is different in Windows (10, 13). Make it portable, by making use of os.EOL semantics Refs: https://github.com/nodejs/node/issues/25988 --- test/parallel/test-child-process-pipe-dataflow.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-child-process-pipe-dataflow.js b/test/parallel/test-child-process-pipe-dataflow.js index bc5e4e02fdf4e9..5f19fa3e4d0602 100644 --- a/test/parallel/test-child-process-pipe-dataflow.js +++ b/test/parallel/test-child-process-pipe-dataflow.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); +const os = require('os'); const spawn = require('child_process').spawn; const tmpdir = require('../common/tmpdir'); @@ -19,14 +20,15 @@ const MB = KB * KB; { tmpdir.refresh(); const file = path.resolve(tmpdir.path, 'data.txt'); - const buf = Buffer.alloc(MB).fill('x'); + let buf = Buffer.alloc(MB).fill('x'); // Most OS commands that deal with data, attach special // meanings to new line - for example, line buffering. // So cut the buffer into lines at some points, forcing // data flow to be split in the stream. + const eol_len = os.EOL.length; for (let i = 0; i < KB; i++) - buf[i * KB] = 10; + buf = buf.fill(os.EOL, i * KB, (i * KB + eol_len)); fs.writeFileSync(file, buf.toString()); cat = spawn('cat', [file]); From 36943ab4b019cf5cf7e8b49cc9825496defdd01f Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Fri, 6 Mar 2020 00:58:07 -0500 Subject: [PATCH 2/4] fixup: address review comment --- test/parallel/test-child-process-pipe-dataflow.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-child-process-pipe-dataflow.js b/test/parallel/test-child-process-pipe-dataflow.js index 5f19fa3e4d0602..1eed8fb2e7e2b2 100644 --- a/test/parallel/test-child-process-pipe-dataflow.js +++ b/test/parallel/test-child-process-pipe-dataflow.js @@ -20,15 +20,14 @@ const MB = KB * KB; { tmpdir.refresh(); const file = path.resolve(tmpdir.path, 'data.txt'); - let buf = Buffer.alloc(MB).fill('x'); + const buf = Buffer.alloc(MB).fill('x'); // Most OS commands that deal with data, attach special // meanings to new line - for example, line buffering. // So cut the buffer into lines at some points, forcing // data flow to be split in the stream. - const eol_len = os.EOL.length; for (let i = 0; i < KB; i++) - buf = buf.fill(os.EOL, i * KB, (i * KB + eol_len)); + buf.write(os.EOL, i * KB); fs.writeFileSync(file, buf.toString()); cat = spawn('cat', [file]); From 8ba9a3145cd4b8ecd85bfe9aca0cfa4bcf0dd26a Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 9 Mar 2020 08:56:35 -0400 Subject: [PATCH 3/4] fixup: fix windows failure --- test/parallel/test-child-process-pipe-dataflow.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-child-process-pipe-dataflow.js b/test/parallel/test-child-process-pipe-dataflow.js index 1eed8fb2e7e2b2..402483fbb7b58b 100644 --- a/test/parallel/test-child-process-pipe-dataflow.js +++ b/test/parallel/test-child-process-pipe-dataflow.js @@ -26,7 +26,7 @@ const MB = KB * KB; // meanings to new line - for example, line buffering. // So cut the buffer into lines at some points, forcing // data flow to be split in the stream. - for (let i = 0; i < KB; i++) + for (let i = 1; i < KB; i++) buf.write(os.EOL, i * KB); fs.writeFileSync(file, buf.toString()); @@ -62,6 +62,7 @@ const MB = KB * KB; }); wc.stdout.on('data', common.mustCall((data) => { - assert.strictEqual(data.toString().trim(), MB.toString()); + // Grep always adds one extra byte at the end. + assert.strictEqual(data.toString().trim(), (MB+1).toString()); })); } From a6f14d96e09e39fc585c9ec2ce6006693871b40d Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 9 Mar 2020 09:03:59 -0400 Subject: [PATCH 4/4] fixup: fix linter error --- test/parallel/test-child-process-pipe-dataflow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-pipe-dataflow.js b/test/parallel/test-child-process-pipe-dataflow.js index 402483fbb7b58b..5f425a6f3d087c 100644 --- a/test/parallel/test-child-process-pipe-dataflow.js +++ b/test/parallel/test-child-process-pipe-dataflow.js @@ -63,6 +63,6 @@ const MB = KB * KB; wc.stdout.on('data', common.mustCall((data) => { // Grep always adds one extra byte at the end. - assert.strictEqual(data.toString().trim(), (MB+1).toString()); + assert.strictEqual(data.toString().trim(), (MB + 1).toString()); })); }