11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { spawn } = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/27097.
71cb0ef41Sopenharmony_ci// Check that (cat [p1] ; cat [p2]) | cat [p3] works.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst p3 = spawn('cat', { stdio: ['pipe', 'pipe', 'inherit'] });
101cb0ef41Sopenharmony_ciconst p1 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] });
111cb0ef41Sopenharmony_ciconst p2 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] });
121cb0ef41Sopenharmony_cip3.stdout.setEncoding('utf8');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// Write three different chunks:
151cb0ef41Sopenharmony_ci// - 'hello' from this process to p1 to p3 back to us
161cb0ef41Sopenharmony_ci// - 'world' from this process to p2 to p3 back to us
171cb0ef41Sopenharmony_ci// - 'foobar' from this process  to p3 back to us
181cb0ef41Sopenharmony_ci// Do so sequentially in order to avoid race conditions.
191cb0ef41Sopenharmony_cip1.stdin.end('hello\n');
201cb0ef41Sopenharmony_cip3.stdout.once('data', common.mustCall((chunk) => {
211cb0ef41Sopenharmony_ci  assert.strictEqual(chunk, 'hello\n');
221cb0ef41Sopenharmony_ci  p2.stdin.end('world\n');
231cb0ef41Sopenharmony_ci  p3.stdout.once('data', common.mustCall((chunk) => {
241cb0ef41Sopenharmony_ci    assert.strictEqual(chunk, 'world\n');
251cb0ef41Sopenharmony_ci    p3.stdin.end('foobar\n');
261cb0ef41Sopenharmony_ci    p3.stdout.once('data', common.mustCall((chunk) => {
271cb0ef41Sopenharmony_ci      assert.strictEqual(chunk, 'foobar\n');
281cb0ef41Sopenharmony_ci    }));
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci}));
31