@@ -19,6 +19,25 @@ const { finished, pipeline } = require("node:stream/promises");
1919
2020const assert = require ( "assert" ) ;
2121const { Given, When, Then } = require ( "@cucumber/cucumber" ) ;
22+ const util = require ( "util" ) ;
23+ const sleep = util . promisify ( setTimeout ) ;
24+
25+ let DB_VERSION = process . env . DB_VERSION ;
26+ if ( DB_VERSION ) {
27+ DB_VERSION = DB_VERSION . split ( "." ) . map ( Number ) ;
28+ } else {
29+ DB_VERSION = [ 100 , 0 , 0 ] ;
30+ }
31+
32+ let DRIVER_VERSION = process . env . DRIVER_VERSION ;
33+ if ( DRIVER_VERSION ) {
34+ DRIVER_VERSION = DRIVER_VERSION . split ( "." ) . map ( Number ) ;
35+ } else {
36+ DRIVER_VERSION = [ 100 , 0 , 0 ] ;
37+ }
38+
39+ process . env . DATABEND_DRIVER_HEARTBEAT_INTERVAL_SECONDS = "1" ;
40+ process . env . RUST_LOG = "warn,databend_driver=debug,databend_client=debug" ;
2241
2342const { Client } = require ( "../index.js" ) ;
2443
@@ -356,7 +375,7 @@ Then("Load file with Streaming and Select should be equal", async function () {
356375 assert . deepEqual ( ret , expected ) ;
357376} ) ;
358377
359- Then ( "Temp table should work with cluster " , async function ( ) {
378+ Then ( "Temp table is cleaned up when conn is dropped " , async function ( ) {
360379 await this . conn . exec ( `create or replace temp table temp_1(a int)` ) ;
361380 await this . conn . exec ( `INSERT INTO temp_1 VALUES (1),(2)` ) ;
362381
@@ -418,6 +437,74 @@ Then("killQuery should return error for non-existent query ID", async function (
418437 // Should get an error for non-existent query
419438 assert . ok ( err instanceof Error , "Should throw an Error object" ) ;
420439 assert . ok ( typeof err . message === "string" && err . message . length > 0 , "Should return meaningful error message" ) ;
421- console . log ( "Expected error for non-existent query:" , err . message ) ;
440+ // console.log("Expected error for non-existent query:", err.message);
422441 }
423442} ) ;
443+
444+ Then ( "Query should not timeout" , { timeout : 30000 } , async function ( ) {
445+ if ( ! ( DRIVER_VERSION > [ 0 , 30 , 3 ] && DB_VERSION >= [ 1 , 2 , 709 ] ) ) {
446+ console . log ( "SKIP" ) ;
447+ return ;
448+ }
449+ const page_size = 10000 ;
450+
451+ const dsn = `databend://root:@localhost:8000/?sslmode=disable&wait_time_secs=3&max_rows_per_page=${ page_size . toString ( ) } ` ;
452+ const client = new Client ( dsn ) ;
453+
454+ const conn = await client . getConn ( ) ;
455+ await conn . exec ( "set http_handler_result_timeout_secs=3" ) ;
456+ const row = await conn . queryRow ( "show settings like 'http_handler_result_timeout_secs'" ) ;
457+ assert . equal ( row . values ( ) [ 1 ] , "3" ) ;
458+
459+ const sql = "select * from numbers(1000000000)" ;
460+ const rows = await conn . queryIter ( sql ) ;
461+
462+ for ( let i = 0 ; i < page_size ; i ++ ) {
463+ const row = await rows . next ( ) ;
464+ assert . notEqual ( row , null , "Row should not be null before sleep" ) ;
465+ }
466+
467+ console . log ( "before sleep" ) ;
468+ await sleep ( 10000 ) ;
469+ console . log ( "after sleep" ) ;
470+
471+ for ( let i = 0 ; i < page_size * 10 ; i ++ ) {
472+ const row = await rows . next ( ) ;
473+ assert . notEqual ( row , null , `Row should not be null after sleep ${ i . toString ( ) } ${ row } ` ) ;
474+ }
475+ //await conn.close();
476+ } ) ;
477+
478+ Then ( "Drop result set should close it" , async function ( ) {
479+ if ( DRIVER_VERSION < [ 0 , 30 , 3 ] ) {
480+ console . log ( "SKIP" ) ;
481+ return ;
482+ }
483+ const dbName = "drop_result_set_js" ;
484+ const n = ( 1n << 50n ) + 1n ;
485+
486+ const conn = await this . client . getConn ( ) ;
487+
488+ await conn . exec ( `create or replace database ${ dbName } ` ) ;
489+ await conn . exec ( `use ${ dbName } ` ) ;
490+
491+ const sql = `select * from numbers(${ n . toString ( ) } )` ;
492+ let rows = await conn . queryIter ( sql ) ;
493+
494+ const firstRow = await rows . next ( ) ;
495+ assert . notEqual ( firstRow , null ) ;
496+
497+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
498+
499+ const processSql = `select count(1) from system.processes where database = '${ dbName } '` ;
500+ const processResult = await this . conn . queryRow ( processSql ) ;
501+ assert . equal ( processResult . values ( ) [ 0 ] , 1 , `processResult = ${ processResult . values ( ) } ` ) ;
502+
503+ rows . close ( ) ;
504+
505+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
506+
507+ const finalResult = await this . conn . queryRow ( processSql ) ;
508+ const finalCount = finalResult . values ( ) [ 0 ] ;
509+ assert . equal ( finalCount , 0 , `processResult = ${ finalCount } ` ) ;
510+ } ) ;
0 commit comments