From 97145e3fea86fa8ec6e36c43196d1ab0d55f310f Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Tue, 15 Oct 2024 11:04:26 +0200 Subject: [PATCH 1/5] Add a console.log in the test client init --- packages/client-common/__tests__/utils/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/client-common/__tests__/utils/client.ts b/packages/client-common/__tests__/utils/client.ts index 59f8795..b65f48d 100644 --- a/packages/client-common/__tests__/utils/client.ts +++ b/packages/client-common/__tests__/utils/client.ts @@ -161,4 +161,5 @@ export async function wakeUpPing(client: ClickHouseClient): Promise { await client.close() process.exit(1) } + console.log(`Service is awake after ${attempts} attempts`) } From a401feeda9deffe5596be3b2bb4b2014e70b1c9c Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Tue, 15 Oct 2024 12:28:35 +0200 Subject: [PATCH 2/5] Use a simple query instead of a ping --- .../client-common/__tests__/utils/client.ts | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/client-common/__tests__/utils/client.ts b/packages/client-common/__tests__/utils/client.ts index b65f48d..acf11ef 100644 --- a/packages/client-common/__tests__/utils/client.ts +++ b/packages/client-common/__tests__/utils/client.ts @@ -24,9 +24,9 @@ beforeAll(async () => { ) if (isCloudTestEnv() && databaseName === undefined) { const cloudInitClient = createTestClient({ - request_timeout: 10_000, + request_timeout: 5_000, }) - await wakeUpPing(cloudInitClient) + await wakeUpQuery(cloudInitClient) databaseName = await createRandomDatabase(cloudInitClient) await cloudInitClient.close() } @@ -136,24 +136,34 @@ export function getTestDatabaseName(): string { } const MaxPingRetries = 30 -export async function wakeUpPing(client: ClickHouseClient): Promise { +export async function wakeUpQuery(client: ClickHouseClient): Promise { let attempts = 1 let lastError: Error | unknown let isAwake = false while (attempts <= MaxPingRetries) { - const result = await client.ping() - isAwake = result.success - if (result.success) { + try { + const rs = await client.query({ + query: 'SELECT number FROM system.numbers LIMIT 1', + format: 'JSONEachRow', + clickhouse_settings: { + wait_end_of_query: 1, + }, + }) + console.log('Got a successful wake-up response:', await rs.json()) + isAwake = true break + } catch (e) { + console.error( + `Service is still waking up, query attempts so far: ${attempts}. Cause:`, + e, + ) + lastError = e + attempts++ } - console.warn( - `Service is still waking up, ping attempts so far: ${attempts}. Cause:`, - result.error, - ) - lastError = result.error - attempts++ } - if (!isAwake) { + if (isAwake) { + console.log(`Service is awake after ${attempts} attempts`) + } else { console.error( `Failed to wake up the service after ${MaxPingRetries} attempts, exiting. Last error:`, lastError, @@ -161,5 +171,4 @@ export async function wakeUpPing(client: ClickHouseClient): Promise { await client.close() process.exit(1) } - console.log(`Service is awake after ${attempts} attempts`) } From 1a829eecb5f75ea9ed37741f987b2703dee98c12 Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Tue, 15 Oct 2024 13:12:44 +0200 Subject: [PATCH 3/5] Increase request_timeout in the cloud init --- packages/client-common/__tests__/utils/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client-common/__tests__/utils/client.ts b/packages/client-common/__tests__/utils/client.ts index acf11ef..ebfc3c6 100644 --- a/packages/client-common/__tests__/utils/client.ts +++ b/packages/client-common/__tests__/utils/client.ts @@ -24,7 +24,7 @@ beforeAll(async () => { ) if (isCloudTestEnv() && databaseName === undefined) { const cloudInitClient = createTestClient({ - request_timeout: 5_000, + request_timeout: 30_000, }) await wakeUpQuery(cloudInitClient) databaseName = await createRandomDatabase(cloudInitClient) From 48098c143e83bf33f8071a99e256d12f029fb92b Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Tue, 15 Oct 2024 13:16:41 +0200 Subject: [PATCH 4/5] One more console.log --- packages/client-common/__tests__/utils/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/client-common/__tests__/utils/client.ts b/packages/client-common/__tests__/utils/client.ts index ebfc3c6..9dddd97 100644 --- a/packages/client-common/__tests__/utils/client.ts +++ b/packages/client-common/__tests__/utils/client.ts @@ -101,6 +101,7 @@ export async function createRandomDatabase( maybeOnCluster = ` ON CLUSTER '{cluster}'` } const ddl = `CREATE DATABASE IF NOT EXISTS ${databaseName}${maybeOnCluster}` + console.log(`\nCreating database ${databaseName} with DDL:\n${ddl}`) await client.command({ query: ddl, clickhouse_settings: { From 607ddad53fde1d215e680a60b0d1226c11bcf079 Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Tue, 15 Oct 2024 13:22:01 +0200 Subject: [PATCH 5/5] Add try-catch --- .../client-common/__tests__/utils/client.ts | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/client-common/__tests__/utils/client.ts b/packages/client-common/__tests__/utils/client.ts index 9dddd97..5b239cf 100644 --- a/packages/client-common/__tests__/utils/client.ts +++ b/packages/client-common/__tests__/utils/client.ts @@ -101,15 +101,26 @@ export async function createRandomDatabase( maybeOnCluster = ` ON CLUSTER '{cluster}'` } const ddl = `CREATE DATABASE IF NOT EXISTS ${databaseName}${maybeOnCluster}` - console.log(`\nCreating database ${databaseName} with DDL:\n${ddl}`) - await client.command({ - query: ddl, - clickhouse_settings: { - wait_end_of_query: 1, - }, - }) - console.log(`\nCreated database ${databaseName}`) - return databaseName + const startTime = Date.now() + try { + console.log(`\nCreating database ${databaseName} with DDL:\n${ddl}`) + await client.command({ + query: ddl, + clickhouse_settings: { + wait_end_of_query: 1, + }, + }) + console.log( + `\nCreated database ${databaseName} after ${Date.now() - startTime} ms`, + ) + return databaseName + } catch (e) { + console.error( + `Failed to create database ${databaseName} after ${Date.now() - startTime} ms`, + e, + ) + process.exit(1) + } } export async function createTable(