Skip to content

Commit 01f85ba

Browse files
committed
parallelize TestContextCancelExec
1 parent a360be7 commit 01f85ba

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

driver_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,16 +2629,16 @@ func TestPingContext(t *testing.T) {
26292629
}
26302630

26312631
func TestContextCancelExec(t *testing.T) {
2632-
runTests(t, dsn, func(dbt *DBTest) {
2633-
dbt.mustExec("CREATE TABLE test (v INTEGER)")
2632+
runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {
2633+
dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)")
26342634
ctx, cancel := context.WithCancel(context.Background())
26352635

26362636
// Delay execution for just a bit until db.ExecContext has begun.
26372637
defer time.AfterFunc(250*time.Millisecond, cancel).Stop()
26382638

26392639
// This query will be canceled.
26402640
startTime := time.Now()
2641-
if _, err := dbt.db.ExecContext(ctx, "INSERT INTO test VALUES (SLEEP(1))"); err != context.Canceled {
2641+
if _, err := dbt.db.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))"); err != context.Canceled {
26422642
dbt.Errorf("expected context.Canceled, got %v", err)
26432643
}
26442644
if d := time.Since(startTime); d > 500*time.Millisecond {
@@ -2650,22 +2650,22 @@ func TestContextCancelExec(t *testing.T) {
26502650

26512651
// Check how many times the query is executed.
26522652
var v int
2653-
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil {
2653+
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil {
26542654
dbt.Fatalf("%s", err.Error())
26552655
}
26562656
if v != 1 { // TODO: need to kill the query, and v should be 0.
26572657
dbt.Skipf("[WARN] expected val to be 1, got %d", v)
26582658
}
26592659

26602660
// Context is already canceled, so error should come before execution.
2661-
if _, err := dbt.db.ExecContext(ctx, "INSERT INTO test VALUES (1)"); err == nil {
2661+
if _, err := dbt.db.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (1)"); err == nil {
26622662
dbt.Error("expected error")
26632663
} else if err.Error() != "context canceled" {
26642664
dbt.Fatalf("unexpected error: %s", err)
26652665
}
26662666

26672667
// The second insert query will fail, so the table has no changes.
2668-
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil {
2668+
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil {
26692669
dbt.Fatalf("%s", err.Error())
26702670
}
26712671
if v != 1 {

0 commit comments

Comments
 (0)