1- import type { ClickHouseClient , Row } from '@clickhouse/client-common'
1+ import type { Row } from '@clickhouse/client-common'
22import { createTestClient } from '@test/utils'
3+ import type { WebClickHouseClient } from '../../src/client'
34
4- describe ( '[Web] abort request' , ( ) => {
5- let client : ClickHouseClient < ReadableStream >
5+ fdescribe ( '[Web] abort request' , ( ) => {
6+ let client : WebClickHouseClient
67
78 beforeEach ( ( ) => {
8- client = createTestClient ( )
9+ client = createTestClient ( ) as unknown as WebClickHouseClient
910 } )
1011
1112 afterEach ( async ( ) => {
@@ -31,23 +32,27 @@ describe('[Web] abort request', () => {
3132
3233 it ( 'cancels a select query while reading response' , async ( ) => {
3334 const controller = new AbortController ( )
35+ let rowCount = 0
3436 const selectPromise = client
3537 . query ( {
36- query : 'SELECT * from system.numbers LIMIT 100000 ' ,
38+ query : 'SELECT number FROM system.numbers LIMIT 1000 ' ,
3739 format : 'JSONCompactEachRow' ,
3840 abort_signal : controller . signal ,
41+ clickhouse_settings : {
42+ // low block size to force streaming 1 row at a time
43+ max_block_size : '1' ,
44+ } ,
3945 } )
4046 . then ( async ( rs ) => {
4147 const reader = rs . stream ( ) . getReader ( )
4248 while ( true ) {
4349 const { done, value : rows } = await reader . read ( )
4450 if ( done ) break
45- ; ( rows as Row [ ] ) . forEach ( ( row : Row ) => {
46- const [ number ] = row . json < [ string ] > ( )
47- // abort when reach number 3
48- if ( number === '3' ) {
51+ ; ( rows as Row [ ] ) . forEach ( ( ) => {
52+ if ( rowCount >= 1 ) {
4953 controller . abort ( )
5054 }
55+ rowCount ++
5156 } )
5257 }
5358 } )
@@ -61,23 +66,27 @@ describe('[Web] abort request', () => {
6166 } )
6267
6368 it ( 'cancels a select query while reading response by closing response stream' , async ( ) => {
69+ let rowCount = 0
6470 const selectPromise = client
6571 . query ( {
66- query : 'SELECT * from system.numbers LIMIT 100000 ' ,
72+ query : 'SELECT number FROM system.numbers LIMIT 3 ' ,
6773 format : 'JSONCompactEachRow' ,
74+ clickhouse_settings : {
75+ // low block size to force streaming 1 row at a time
76+ max_block_size : '1' ,
77+ } ,
6878 } )
6979 . then ( async function ( rs ) {
7080 const reader = rs . stream ( ) . getReader ( )
7181 while ( true ) {
7282 const { done, value : rows } = await reader . read ( )
7383 if ( done ) break
7484 for ( const row of rows as Row [ ] ) {
75- const [ number ] = row . json < [ string ] > ( )
76- // abort when reach number 3
77- if ( number === '3' ) {
78- await reader . releaseLock ( )
79- await rs . close ( )
85+ row . json ( )
86+ if ( rowCount >= 1 ) {
87+ await rs . stream ( ) . cancel ( )
8088 }
89+ rowCount ++
8190 }
8291 }
8392 } )
0 commit comments