From c122c42c2dd61819db31e4c303adc53eb731e254 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 4 Oct 2022 00:29:19 +0800 Subject: [PATCH] test: fixed an issue with test timeout as stream wasn't ready --- test/node/query.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/node/query.js b/test/node/query.js index ec614a35b..dfa0efd75 100644 --- a/test/node/query.js +++ b/test/node/query.js @@ -200,8 +200,7 @@ describe('req.query(Object)', () => { }); }); - it('query-string should be sent on pipe', function (done) { - this.timeout(15_000); + it('query-string should be sent on pipe', (done) => { const request_ = request.put(`${base}/?name=tobi`); const stream = fs.createReadStream('test/node/fixtures/user.json'); @@ -213,9 +212,16 @@ describe('req.query(Object)', () => { done(err); }); - stream.on('error', function (err) { + stream.on('error', (err) => { done(err); }); - stream.pipe(request_); + + // wait until stream is valid before piping + stream.on('open', () => { + // wait until request_ is ready before piping + setTimeout(() => { + stream.pipe(request_); + }, 10); + }); }); });