aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_go18_test.go
diff options
context:
space:
mode:
authorNiklas Janlert <njanlert@planview.com>2017-11-21 13:40:00 +0100
committerNiklas Janlert <njanlert@planview.com>2017-11-21 13:40:00 +0100
commit58004848f1e59b2cef8add95bf5d13063ce4e003 (patch)
tree5bbecb2957b97369fa15b4be9b8f31f5847281a3 /sqlite3_go18_test.go
parentMerge pull request #485 from mattn/sqlite3-3.21.0 (diff)
downloadgolite-58004848f1e59b2cef8add95bf5d13063ce4e003.tar.gz
golite-58004848f1e59b2cef8add95bf5d13063ce4e003.tar.xz
Fix race in ExecContext
When the context is cancelled, an interrupt should only be made if the operation is still ongoing.
Diffstat (limited to 'sqlite3_go18_test.go')
-rw-r--r--sqlite3_go18_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/sqlite3_go18_test.go b/sqlite3_go18_test.go
index 2662fcf..44fc4df 100644
--- a/sqlite3_go18_test.go
+++ b/sqlite3_go18_test.go
@@ -134,3 +134,24 @@ func TestShortTimeout(t *testing.T) {
t.Fatal(ctx.Err())
}
}
+
+func TestExecCancel(t *testing.T) {
+ db, err := sql.Open("sqlite3", ":memory:")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer db.Close()
+
+ if _, err = db.Exec("create table foo (id integer primary key)"); err != nil {
+ t.Fatal(err)
+ }
+
+ for n := 0; n < 100; n++ {
+ ctx, cancel := context.WithCancel(context.Background())
+ _, err = db.ExecContext(ctx, "insert into foo (id) values (?)", n)
+ cancel()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+}