(t *testing.T)
| 2857 | } |
| 2858 | |
| 2859 | func TestContextCancelStmtQuery(t *testing.T) { |
| 2860 | runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { |
| 2861 | dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") |
| 2862 | ctx, cancel := context.WithCancel(context.Background()) |
| 2863 | stmt, err := dbt.db.PrepareContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))") |
| 2864 | if err != nil { |
| 2865 | dbt.Fatalf("unexpected error: %v", err) |
| 2866 | } |
| 2867 | |
| 2868 | // Delay execution for just a bit until db.ExecContext has begun. |
| 2869 | defer time.AfterFunc(250*time.Millisecond, cancel).Stop() |
| 2870 | |
| 2871 | // This query will be canceled. |
| 2872 | startTime := time.Now() |
| 2873 | if _, err := stmt.QueryContext(ctx); err != context.Canceled { |
| 2874 | dbt.Errorf("expected context.Canceled, got %v", err) |
| 2875 | } |
| 2876 | if d := time.Since(startTime); d > 500*time.Millisecond { |
| 2877 | dbt.Errorf("too long execution time: %s", d) |
| 2878 | } |
| 2879 | |
| 2880 | // Wait for the INSERT query has done. |
| 2881 | time.Sleep(time.Second) |
| 2882 | |
| 2883 | // Check how many times the query is executed. |
| 2884 | var v int |
| 2885 | if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { |
| 2886 | dbt.Fatalf("%s", err.Error()) |
| 2887 | } |
| 2888 | if v != 1 { // TODO: need to kill the query, and v should be 0. |
| 2889 | dbt.Skipf("[WARN] expected val to be 1, got %d", v) |
| 2890 | } |
| 2891 | }) |
| 2892 | } |
| 2893 | |
| 2894 | func TestContextCancelBegin(t *testing.T) { |
| 2895 | if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { |
nothing calls this directly
no test coverage detected
searching dependent graphs…