Skip to content

Commit 3deb8b4

Browse files
committed
parallelize TestContextCancelQuery
1 parent 06c953a commit 3deb8b4

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
@@ -2675,16 +2675,16 @@ func TestContextCancelExec(t *testing.T) {
26752675
}
26762676

26772677
func TestContextCancelQuery(t *testing.T) {
2678-
runTests(t, dsn, func(dbt *DBTest) {
2679-
dbt.mustExec("CREATE TABLE test (v INTEGER)")
2678+
runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {
2679+
dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)")
26802680
ctx, cancel := context.WithCancel(context.Background())
26812681

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

26852685
// This query will be canceled.
26862686
startTime := time.Now()
2687-
if _, err := dbt.db.QueryContext(ctx, "INSERT INTO test VALUES (SLEEP(1))"); err != context.Canceled {
2687+
if _, err := dbt.db.QueryContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))"); err != context.Canceled {
26882688
dbt.Errorf("expected context.Canceled, got %v", err)
26892689
}
26902690
if d := time.Since(startTime); d > 500*time.Millisecond {
@@ -2696,20 +2696,20 @@ func TestContextCancelQuery(t *testing.T) {
26962696

26972697
// Check how many times the query is executed.
26982698
var v int
2699-
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil {
2699+
if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil {
27002700
dbt.Fatalf("%s", err.Error())
27012701
}
27022702
if v != 1 { // TODO: need to kill the query, and v should be 0.
27032703
dbt.Skipf("[WARN] expected val to be 1, got %d", v)
27042704
}
27052705

27062706
// Context is already canceled, so error should come before execution.
2707-
if _, err := dbt.db.QueryContext(ctx, "INSERT INTO test VALUES (1)"); err != context.Canceled {
2707+
if _, err := dbt.db.QueryContext(ctx, "INSERT INTO "+tbl+" VALUES (1)"); err != context.Canceled {
27082708
dbt.Errorf("expected context.Canceled, got %v", err)
27092709
}
27102710

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

0 commit comments

Comments
 (0)