Remove tests context cancel
Context cancellation is now fatal so no need to test recovery.
This commit is contained in:
-116
@@ -215,122 +215,6 @@ func TestConnBeginBatchWithPreparedStatement(t *testing.T) {
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestConnBeginBatchContextCancelBeforeExecResults(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
|
||||
sql := `create temporary table ledger(
|
||||
id serial primary key,
|
||||
description varchar not null,
|
||||
amount int not null
|
||||
);`
|
||||
mustExec(t, conn, sql)
|
||||
|
||||
batch := conn.BeginBatch()
|
||||
batch.Queue("insert into ledger(description, amount) values($1, $2)",
|
||||
[]interface{}{"q1", 1},
|
||||
[]pgtype.OID{pgtype.VarcharOID, pgtype.Int4OID},
|
||||
nil,
|
||||
)
|
||||
batch.Queue("select pg_sleep(2)",
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
ctx, cancelFn := context.WithCancel(context.Background())
|
||||
|
||||
err := batch.Send(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cancelFn()
|
||||
|
||||
_, err = batch.ExecResults()
|
||||
if err != context.Canceled {
|
||||
t.Errorf("err => %v, want %v", err, context.Canceled)
|
||||
}
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestConnBeginBatchContextCancelBeforeQueryResults(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
|
||||
batch := conn.BeginBatch()
|
||||
batch.Queue("select pg_sleep(2)",
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
batch.Queue("select pg_sleep(2)",
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
ctx, cancelFn := context.WithCancel(context.Background())
|
||||
|
||||
err := batch.Send(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cancelFn()
|
||||
|
||||
rows, err := batch.QueryResults()
|
||||
|
||||
if rows.Next() {
|
||||
t.Error("unexpected row")
|
||||
}
|
||||
|
||||
if rows.Err() != context.Canceled {
|
||||
t.Errorf("rows.Err() => %v, want %v", rows.Err(), context.Canceled)
|
||||
}
|
||||
|
||||
batch.Close()
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestConnBeginBatchContextCancelBeforeFinish(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
|
||||
batch := conn.BeginBatch()
|
||||
batch.Queue("select pg_sleep(2)",
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
batch.Queue("select pg_sleep(2)",
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
ctx, cancelFn := context.WithCancel(context.Background())
|
||||
|
||||
err := batch.Send(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cancelFn()
|
||||
|
||||
err = batch.Close()
|
||||
if err != context.Canceled {
|
||||
t.Errorf("err => %v, want %v", err, context.Canceled)
|
||||
}
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestConnBeginBatchCloseRowsPartiallyRead(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user