-
Notifications
You must be signed in to change notification settings - Fork 90
/
stmt_go18_test.go
47 lines (41 loc) · 1.38 KB
/
stmt_go18_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
//go:build go1.8
// +build go1.8
package clickhouse
import (
"context"
"database/sql/driver"
"time"
)
var (
_ driver.StmtExecContext = new(stmt)
_ driver.StmtQueryContext = new(stmt)
)
func (s *stmtSuite) TestQueryContext() {
ctx, cancel := context.WithCancel(context.Background())
st, err := s.conn.PrepareContext(ctx, "SELECT sleep(?)")
s.Require().NoError(err)
time.AfterFunc(5*time.Millisecond, cancel)
_, err = st.QueryContext(ctx, 3)
s.EqualError(err, "doRequest: transport failed to send a request to ClickHouse: context canceled")
s.NoError(st.Close())
}
func (s *stmtSuite) TestExecContext() {
ctx, cancel := context.WithCancel(context.Background())
st, err := s.conn.PrepareContext(ctx, "SELECT sleep(?)")
s.Require().NoError(err)
time.AfterFunc(5*time.Millisecond, cancel)
_, err = st.ExecContext(ctx, 3)
s.EqualError(err, "doRequest: transport failed to send a request to ClickHouse: context canceled")
s.NoError(st.Close())
}
func (s *stmtSuite) TestExecMultiContext() {
ctx, cancel := context.WithCancel(context.Background())
tx, err := s.conn.BeginTx(ctx, nil)
s.Require().NoError(err)
st, err := tx.PrepareContext(ctx, "SELECT sleep(?)")
s.Require().NoError(err)
time.AfterFunc(10*time.Millisecond, cancel)
_, err = st.ExecContext(ctx, 3)
s.EqualError(err, "doRequest: transport failed to send a request to ClickHouse: context canceled")
s.NoError(st.Close())
}