@@ -2675,16 +2675,16 @@ func TestContextCancelExec(t *testing.T) {
2675
2675
}
2676
2676
2677
2677
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)" )
2680
2680
ctx , cancel := context .WithCancel (context .Background ())
2681
2681
2682
2682
// Delay execution for just a bit until db.ExecContext has begun.
2683
2683
defer time .AfterFunc (250 * time .Millisecond , cancel ).Stop ()
2684
2684
2685
2685
// This query will be canceled.
2686
2686
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 {
2688
2688
dbt .Errorf ("expected context.Canceled, got %v" , err )
2689
2689
}
2690
2690
if d := time .Since (startTime ); d > 500 * time .Millisecond {
@@ -2696,20 +2696,20 @@ func TestContextCancelQuery(t *testing.T) {
2696
2696
2697
2697
// Check how many times the query is executed.
2698
2698
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 {
2700
2700
dbt .Fatalf ("%s" , err .Error ())
2701
2701
}
2702
2702
if v != 1 { // TODO: need to kill the query, and v should be 0.
2703
2703
dbt .Skipf ("[WARN] expected val to be 1, got %d" , v )
2704
2704
}
2705
2705
2706
2706
// 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 {
2708
2708
dbt .Errorf ("expected context.Canceled, got %v" , err )
2709
2709
}
2710
2710
2711
2711
// 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 {
2713
2713
dbt .Fatalf ("%s" , err .Error ())
2714
2714
}
2715
2715
if v != 1 {
0 commit comments