diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/lib/pq@v1.10.7/issues_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/lib/pq@v1.10.7/issues_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/issues_test.go b/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/issues_test.go new file mode 100644 index 0000000..26a7028 --- /dev/null +++ b/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/issues_test.go @@ -0,0 +1,81 @@ +package pq + +import ( + "context" + "errors" + "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() + } + if pgErr := (*Error)(nil); !(errors.As(err, &pgErr) && pgErr.Code == cancelErrorCode) { + t.Logf("ctx.Err(): [%T]%+v\n", ctx.Err(), ctx.Err()) + t.Logf("got err: [%T] %+v expected errCode: %v", err, err, cancelErrorCode) + 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 < 100; i++ { + ctx, cancel := context.WithCancel(context.Background()) + go cancel() + row := db.QueryRowContext(ctx, "select 1") + + var v int + err := row.Scan(&v) + if pgErr := (*Error)(nil); err != nil && + err != context.Canceled && + !(errors.As(err, &pgErr) && pgErr.Code == cancelErrorCode) { + t.Fatalf("Scan resulted in unexpected error %v for canceled QueryRowContext at attempt %d", err, i+1) + } + } +} |