@@ -2629,16 +2629,16 @@ func TestPingContext(t *testing.T) {
2629
2629
}
2630
2630
2631
2631
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)" )
2634
2634
ctx , cancel := context .WithCancel (context .Background ())
2635
2635
2636
2636
// Delay execution for just a bit until db.ExecContext has begun.
2637
2637
defer time .AfterFunc (250 * time .Millisecond , cancel ).Stop ()
2638
2638
2639
2639
// This query will be canceled.
2640
2640
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 {
2642
2642
dbt .Errorf ("expected context.Canceled, got %v" , err )
2643
2643
}
2644
2644
if d := time .Since (startTime ); d > 500 * time .Millisecond {
@@ -2650,22 +2650,22 @@ func TestContextCancelExec(t *testing.T) {
2650
2650
2651
2651
// Check how many times the query is executed.
2652
2652
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 {
2654
2654
dbt .Fatalf ("%s" , err .Error ())
2655
2655
}
2656
2656
if v != 1 { // TODO: need to kill the query, and v should be 0.
2657
2657
dbt .Skipf ("[WARN] expected val to be 1, got %d" , v )
2658
2658
}
2659
2659
2660
2660
// 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 {
2662
2662
dbt .Error ("expected error" )
2663
2663
} else if err .Error () != "context canceled" {
2664
2664
dbt .Fatalf ("unexpected error: %s" , err )
2665
2665
}
2666
2666
2667
2667
// 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 {
2669
2669
dbt .Fatalf ("%s" , err .Error ())
2670
2670
}
2671
2671
if v != 1 {
0 commit comments