forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stmt_go18_test.go
46 lines (40 loc) · 1.36 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
// +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())
}