From b263402091465f07c1d90d70a556cb406a8b193f Mon Sep 17 00:00:00 2001 From: nofarham <116541220+nofarham@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:13:02 +0200 Subject: [PATCH 1/4] Fix node 18 (based on #711) --- lib/commands/query.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/query.js b/lib/commands/query.js index 0de52ff05a..1b3725d73f 100644 --- a/lib/commands/query.js +++ b/lib/commands/query.js @@ -279,7 +279,7 @@ class Query extends Command { }); this.on('end', () => { stream.push(null); // pushing null, indicating EOF - stream.emit('close'); // notify readers that query has completed + setImmediate(() => stream.emit('close')); // notify readers that query has completed }); this.on('fields', fields => { stream.emit('fields', fields); // replicate old emitter From 97f15071a291f166942d49c0942aedaa2e023307 Mon Sep 17 00:00:00 2001 From: nofarham <116541220+nofarham@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:16:26 +0200 Subject: [PATCH 2/4] Add tests to query stream --- test/integration/connection/test-stream.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/connection/test-stream.js b/test/integration/connection/test-stream.js index 133acc8426..2ddb62b3fc 100644 --- a/test/integration/connection/test-stream.js +++ b/test/integration/connection/test-stream.js @@ -7,6 +7,7 @@ const assert = require('assert'); let rows; const rows1 = []; const rows2 = []; +const rows3 = []; connection.query( [ @@ -62,8 +63,14 @@ connection.execute('SELECT * FROM announcements', (err, _rows) => { }); }); +const s3 = connection.query('SELECT * FROM announcements').stream(); +for await (const row of s3) { + rows3.push(row); +} + process.on('exit', () => { assert.deepEqual(rows.length, 2); assert.deepEqual(rows, rows1); assert.deepEqual(rows, rows2); + assert.deepEqual(rows, rows3); }); From 163532d3e839dd5c3c1a12c36405e9909c800484 Mon Sep 17 00:00:00 2001 From: nofarham <116541220+nofarham@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:23:57 +0200 Subject: [PATCH 3/4] fix async error --- test/integration/connection/test-stream.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/integration/connection/test-stream.js b/test/integration/connection/test-stream.js index 2ddb62b3fc..75a52a98a3 100644 --- a/test/integration/connection/test-stream.js +++ b/test/integration/connection/test-stream.js @@ -46,7 +46,7 @@ connection.execute( } } ); -connection.execute('SELECT * FROM announcements', (err, _rows) => { +connection.execute('SELECT * FROM announcements', async (err, _rows) => { rows = _rows; const s1 = connection.query('SELECT * FROM announcements').stream(); s1.on('data', row => { @@ -61,13 +61,12 @@ connection.execute('SELECT * FROM announcements', (err, _rows) => { connection.end(); }); }); + const s3 = connection.query('SELECT * FROM announcements').stream(); + for await (const row of s3) { + rows3.push(row); + } }); -const s3 = connection.query('SELECT * FROM announcements').stream(); -for await (const row of s3) { - rows3.push(row); -} - process.on('exit', () => { assert.deepEqual(rows.length, 2); assert.deepEqual(rows, rows1); From b997c91d7d70ec7d3ddb02a519340efc6df921d1 Mon Sep 17 00:00:00 2001 From: nofarham <116541220+nofarham@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:39:13 +0200 Subject: [PATCH 4/4] fix indentation --- test/integration/connection/test-stream.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/connection/test-stream.js b/test/integration/connection/test-stream.js index 75a52a98a3..57ac6dd5ba 100644 --- a/test/integration/connection/test-stream.js +++ b/test/integration/connection/test-stream.js @@ -61,10 +61,10 @@ connection.execute('SELECT * FROM announcements', async (err, _rows) => { connection.end(); }); }); - const s3 = connection.query('SELECT * FROM announcements').stream(); - for await (const row of s3) { - rows3.push(row); - } + const s3 = connection.query('SELECT * FROM announcements').stream(); + for await (const row of s3) { + rows3.push(row); + } }); process.on('exit', () => {