14 Star 21 Fork 16

openGauss/openGauss-connector-go-pq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
issues_test.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
travelliu 提交于 2022-04-15 10:41 . feat: support blob type
package pq
import (
"context"
"testing"
"time"
)
func TestIssue494(t *testing.T) {
db := openTestConn(t)
defer db.Close()
query := `CREATE TEMP TABLE t (i INT PRIMARY KEY)`
if _, err := db.Exec(query); err != nil {
t.Fatal(err)
}
txn, err := db.Begin()
if err != nil {
t.Fatal(err)
}
if _, err := txn.Prepare(CopyIn("t", "i")); err != nil {
t.Fatal(err)
}
if _, err := txn.Query("SELECT 1"); err == nil {
t.Fatal("expected error")
}
}
func TestIssue1046(t *testing.T) {
ctxTimeout := time.Second * 2
db := openTestConn(t)
defer db.Close()
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()
stmt, err := db.PrepareContext(ctx, `SELECT pg_sleep(10) AS id`)
if err != nil {
t.Fatal(err)
}
var d []uint8
err = stmt.QueryRowContext(ctx).Scan(&d)
dl, _ := ctx.Deadline()
since := time.Since(dl)
if since > ctxTimeout {
t.Logf("FAIL %s: query returned after context deadline: %v\n", t.Name(), since)
t.Fail()
}
expectedErr := &Error{Message: "canceling statement due to user request"}
if err == nil || err.Error() != expectedErr.Error() {
t.Logf("ctx.Err(): [%T]%+v\n", ctx.Err(), ctx.Err())
t.Logf("got err: [%T] %+v expected err: [%T] %+v", err, err, expectedErr, expectedErr)
t.Fail()
}
}
func TestIssue1062(t *testing.T) {
db := openTestConn(t)
defer db.Close()
// Ensure that cancelling a QueryRowContext does not result in an ErrBadConn.
for i := 0; i < 10; i++ {
ctx, cancel := context.WithCancel(context.Background())
go cancel()
row := db.QueryRowContext(ctx, "select 1")
var v int
err := row.Scan(&v)
if err != nil && err != context.Canceled && err.Error() != "pq: canceling statement due to user request" {
t.Fatalf("Scan resulted in unexpected error %v for canceled QueryRowContext at attempt %d", err, i+1)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opengauss/openGauss-connector-go-pq.git
git@gitee.com:opengauss/openGauss-connector-go-pq.git
opengauss
openGauss-connector-go-pq
openGauss-connector-go-pq
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385