-
Notifications
You must be signed in to change notification settings - Fork 30
/
node_summary.test.ts
98 lines (92 loc) · 3.08 KB
/
node_summary.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import type { ClickHouseClient } from '@clickhouse/client-common'
import { createSimpleTable } from '@test/fixtures/simple_table'
import { jsonValues } from '@test/fixtures/test_data'
import { createTestClient, guid, TestEnv, whenOnEnv } from '@test/utils'
import type Stream from 'stream'
// FIXME: figure out if we can get non-flaky assertion with an SMT Cloud instance.
// It could be that it requires full quorum settings for non-flaky assertions.
// SharedMergeTree Cloud instance is auto by default (and cannot be modified).
whenOnEnv(
TestEnv.LocalSingleNode,
TestEnv.LocalCluster,
TestEnv.Cloud,
).describe('[Node.js] Summary header parsing', () => {
let client: ClickHouseClient<Stream.Readable>
let tableName: string
beforeAll(async () => {
client = createTestClient()
tableName = `summary_test_${guid()}`
await createSimpleTable(client, tableName)
})
afterAll(async () => {
await client.close()
})
it('should provide summary for insert/exec', async () => {
const { summary: insertSummary } = await client.insert({
table: tableName,
values: jsonValues,
format: 'JSONEachRow',
})
expect(insertSummary).toEqual(
jasmine.objectContaining({
read_rows: '5',
read_bytes: jasmine.any(String),
written_rows: '5',
written_bytes: jasmine.any(String),
total_rows_to_read: '0',
result_rows: '5',
result_bytes: jasmine.any(String),
elapsed_ns: jasmine.any(String),
}),
)
assertRealTimeMicroseconds(insertSummary)
const { summary: execSummary } = await client.exec({
query: `INSERT INTO ${tableName}
SELECT *
FROM ${tableName}`,
})
expect(execSummary).toEqual(
jasmine.objectContaining({
read_rows: '5',
read_bytes: jasmine.any(String),
written_rows: '5',
written_bytes: jasmine.any(String),
total_rows_to_read: '5',
result_rows: '5',
result_bytes: jasmine.any(String),
elapsed_ns: jasmine.any(String),
}),
)
assertRealTimeMicroseconds(execSummary)
})
it('should provide summary for command', async () => {
const { summary } = await client.command({
query: `INSERT INTO ${tableName}
VALUES (144, 'Hello', [2, 4]),
(255, 'World', [3, 5])`,
clickhouse_settings: {
wait_end_of_query: 1,
},
})
expect(summary).toEqual(
jasmine.objectContaining({
read_rows: '2',
read_bytes: jasmine.any(String),
written_rows: '2',
written_bytes: jasmine.any(String),
total_rows_to_read: '0',
result_rows: '2',
result_bytes: jasmine.any(String),
elapsed_ns: jasmine.any(String),
}),
)
assertRealTimeMicroseconds(summary)
})
function assertRealTimeMicroseconds(summary: any) {
// FIXME: remove this condition after 24.9 is released
if (process.env['CLICKHOUSE_VERSION'] === 'head') {
expect(summary.real_time_microseconds).toBeDefined()
expect(summary.real_time_microseconds).toMatch(/^\d+$/)
}
}
})