From c80d3c4a974d639a7684de94b46071c3b0bf4b38 Mon Sep 17 00:00:00 2001 From: Elliana May Date: Wed, 7 Jun 2023 20:22:18 +0800 Subject: [PATCH 1/3] fix(nodejs): another http state error --- src/main/client_context.cpp | 2 ++ tools/nodejs/test/extension.test.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/client_context.cpp b/src/main/client_context.cpp index b1ad53a681c..9a56ff7249d 100644 --- a/src/main/client_context.cpp +++ b/src/main/client_context.cpp @@ -319,6 +319,8 @@ shared_ptr ClientContext::CreatePreparedStatement(ClientC planner.parameter_data.emplace_back(value); } } + + client_data->http_state = make_uniq(); planner.CreatePlan(std::move(statement)); D_ASSERT(planner.plan || !planner.properties.bound_all_parameters); profiler.EndPhase(); diff --git a/tools/nodejs/test/extension.test.ts b/tools/nodejs/test/extension.test.ts index 3af8687a409..e3b0d077b11 100644 --- a/tools/nodejs/test/extension.test.ts +++ b/tools/nodejs/test/extension.test.ts @@ -44,6 +44,13 @@ const test_httpfs = async function (db: duckdb.Database) { } })); + await new Promise((resolve, reject) => { + db.exec(`SELECT * + FROM parquet_scan('http://localhost:1234/whatever.parquet')`, function (err: DuckDbError | null) { + err ? reject(err) : resolve() + }); + }) + await new Promise((resolve) => { db.exec("select * from read_csv_auto('https://example.com/hello.csv')", (err: DuckDbError | null) => { assert.ok(err); From d9efd1608f1623000c75ebb87ee2dccdf9ed1733 Mon Sep 17 00:00:00 2001 From: Elliana May Date: Wed, 7 Jun 2023 22:44:49 +0800 Subject: [PATCH 2/3] test(nodejs): test for http state --- tools/nodejs/package.json | 2 ++ tools/nodejs/test/extension.test.ts | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/nodejs/package.json b/tools/nodejs/package.json index c5cd43d53b8..a6b866129ca 100644 --- a/tools/nodejs/package.json +++ b/tools/nodejs/package.json @@ -28,11 +28,13 @@ }, "devDependencies": { "@types/chai": "^4.3.4", + "@types/chai-as-promised": "^7.1.5", "@types/mocha": "^10.0.0", "@types/node": "^18.11.0", "apache-arrow": "^9.0.0", "aws-sdk": "^2.790.0", "chai": "^4.3.6", + "chai-as-promised": "^7.1.1", "jsdoc3-parser": "^2.0.0", "mocha": "^8.3.0", "ts-node": "^10.9.1", diff --git a/tools/nodejs/test/extension.test.ts b/tools/nodejs/test/extension.test.ts index e3b0d077b11..435622a3bc4 100644 --- a/tools/nodejs/test/extension.test.ts +++ b/tools/nodejs/test/extension.test.ts @@ -3,6 +3,10 @@ import {Database, DuckDbError, HttpError, TableData} from '..'; import * as fs from 'fs'; import * as assert from 'assert'; import * as path from 'path'; +import chaiAsPromised from 'chai-as-promised'; +import chai, {expect} from "chai"; + +chai.use(chaiAsPromised); const extension_base_path = "../../../build/release/extension"; @@ -26,6 +30,13 @@ function isHTTPException(err: DuckDbError): err is HttpError { // Note: test will pass on http request failing due to connection issues. const test_httpfs = async function (db: duckdb.Database) { + const promise = new Promise((resolve, reject) => + db.exec(`SELECT * + FROM parquet_scan('http://localhost:1234/whatever.parquet')`, function (err: DuckDbError | null) { + err ? reject(err) : resolve() + })); + await chai.assert.isRejected(promise, 'IO Error: Connection error for HTTP HEAD'); + await new Promise((resolve, reject) => db.all("SELECT id, first_name, last_name FROM PARQUET_SCAN('https://raw.githubusercontent.com/cwida/duckdb/master/data/parquet-testing/userdata1.parquet') LIMIT 3;", function (err: null | Error, rows: TableData) { if (err) { if (err.message.startsWith("Unable to connect to URL")) { @@ -44,13 +55,6 @@ const test_httpfs = async function (db: duckdb.Database) { } })); - await new Promise((resolve, reject) => { - db.exec(`SELECT * - FROM parquet_scan('http://localhost:1234/whatever.parquet')`, function (err: DuckDbError | null) { - err ? reject(err) : resolve() - }); - }) - await new Promise((resolve) => { db.exec("select * from read_csv_auto('https://example.com/hello.csv')", (err: DuckDbError | null) => { assert.ok(err); From f919df4d25662caddfe0971dbde9277d6bc47724 Mon Sep 17 00:00:00 2001 From: Elliana May Date: Fri, 9 Jun 2023 14:49:40 +0800 Subject: [PATCH 3/3] fix: shared, not unique not sure how this happened --- src/main/client_context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/client_context.cpp b/src/main/client_context.cpp index 9a56ff7249d..b6b85ecc8fa 100644 --- a/src/main/client_context.cpp +++ b/src/main/client_context.cpp @@ -320,7 +320,7 @@ shared_ptr ClientContext::CreatePreparedStatement(ClientC } } - client_data->http_state = make_uniq(); + client_data->http_state = make_shared(); planner.CreatePlan(std::move(statement)); D_ASSERT(planner.plan || !planner.properties.bound_all_parameters); profiler.EndPhase();