Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI fixes #338

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions packages/client-common/__tests__/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ beforeAll(async () => {
)
if (isCloudTestEnv() && databaseName === undefined) {
const cloudInitClient = createTestClient({
request_timeout: 10_000,
request_timeout: 30_000,
})
await wakeUpPing(cloudInitClient)
await wakeUpQuery(cloudInitClient)
databaseName = await createRandomDatabase(cloudInitClient)
await cloudInitClient.close()
}
Expand Down Expand Up @@ -101,14 +101,26 @@ export async function createRandomDatabase(
maybeOnCluster = ` ON CLUSTER '{cluster}'`
}
const ddl = `CREATE DATABASE IF NOT EXISTS ${databaseName}${maybeOnCluster}`
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<Stream = unknown>(
Expand Down Expand Up @@ -136,24 +148,34 @@ export function getTestDatabaseName(): string {
}

const MaxPingRetries = 30
export async function wakeUpPing(client: ClickHouseClient): Promise<void> {
export async function wakeUpQuery(client: ClickHouseClient): Promise<void> {
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,
Expand Down
Loading