-
Notifications
You must be signed in to change notification settings - Fork 11
/
profile_test.go
92 lines (85 loc) · 2.5 KB
/
profile_test.go
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
package chconn
import (
"context"
"errors"
"fmt"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vahid-sohrabloo/chconn/v2/column"
"github.com/vahid-sohrabloo/chconn/v2/internal/helper"
)
func TestProfileReadError(t *testing.T) {
startValidReader := 43
config, err := ParseConfig(os.Getenv("CHX_TEST_TCP_CONN_STRING"))
require.NoError(t, err)
c, err := ConnectConfig(context.Background(), config)
require.NoError(t, err)
if c.ServerInfo().Revision >= helper.DbmsMinProtocolWithServerQueryTimeInProgress {
// todo we need to fix this for clickhouse 22.10 and above
return
}
tests := []struct {
name string
wantErr string
numberValid int
}{
{
name: "profile: read Rows",
wantErr: "profile: read Rows",
numberValid: startValidReader,
}, {
name: "profile: read Blocks",
wantErr: "profile: read Blocks",
numberValid: startValidReader + 1,
}, {
name: "profile: read Bytes",
wantErr: "profile: read Bytes",
numberValid: startValidReader + 2,
}, {
name: "profile: read AppliedLimit",
wantErr: "profile: read AppliedLimit",
numberValid: startValidReader + 3,
}, {
name: "profile: read RowsBeforeLimit",
wantErr: "profile: read RowsBeforeLimit",
numberValid: startValidReader + 4,
}, {
name: "profile: read CalculatedRowsBeforeLimit",
wantErr: "profile: read CalculatedRowsBeforeLimit",
numberValid: startValidReader + 5,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := ParseConfig(os.Getenv("CHX_TEST_TCP_CONN_STRING"))
require.NoError(t, err)
if c.ServerInfo().Revision >= helper.DbmsMinProtocolWithServerQueryTimeInProgress {
tt.numberValid++
}
config.ReaderFunc = func(r io.Reader) io.Reader {
return &readErrorHelper{
err: errors.New("timeout"),
r: r,
numberValid: tt.numberValid,
}
}
c, err := ConnectConfig(context.Background(), config)
require.NoError(t, err)
col := column.New[uint64]()
stmt, err := c.Select(context.Background(), "SELECT * FROM system.numbers LIMIT 1;", col)
require.NoError(t, err)
for stmt.Next() {
}
require.Error(t, stmt.Err())
readErr, ok := stmt.Err().(*readError)
require.True(t, ok)
fmt.Println("readErr.msg:", readErr.msg)
require.Equal(t, tt.wantErr, readErr.msg)
require.EqualError(t, readErr.Unwrap(), "timeout")
assert.True(t, c.IsClosed())
})
}
}