Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package sqlite_test
import (
"bytes"
"context"
"errors"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -864,3 +865,29 @@ func TestReturningClause(t *testing.T) {
t.Fatalf("want returned fruit id to be 1, got %d", id)
}
}

// See https://github.com/crawshaw/sqlite/issues/119 and
// https://github.com/zombiezen/go-sqlite/issues/14
func TestConnWALClose(t *testing.T) {
dbName := filepath.Join(t.TempDir(), "wal-close.db")
conn, err := sqlite.OpenConn(dbName, 0)
if err != nil {
t.Fatal(err)
}
done := make(chan struct{})
conn.SetInterrupt(done)
err = sqlitex.ExecTransient(conn, `CREATE TABLE foo (id integer primary key);`, nil)
if err != nil {
t.Error(err)
}
if _, err := os.Stat(dbName + "-wal"); err != nil {
t.Error(err)
}
close(done)
if err := conn.Close(); err != nil {
t.Error(err)
}
if _, err := os.Stat(dbName + "-wal"); !errors.Is(err, os.ErrNotExist) {
t.Error("wal file should not exist after close")
}
}
28 changes: 28 additions & 0 deletions sqlitex/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package sqlitex_test

import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -302,3 +303,30 @@ func TestPoolOpenInit(t *testing.T) {
t.Fatal("a cancelled context should interrupt initialization")
})
}

// See https://github.com/crawshaw/sqlite/issues/119 and
// https://github.com/zombiezen/go-sqlite/issues/14
func TestPoolWALClose(t *testing.T) {
dbName := filepath.Join(t.TempDir(), "wal-close.db")
pool, err := sqlitex.Open(dbName, 0, 10)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
conn := pool.Get(ctx)
if _, err := os.Stat(dbName + "-wal"); err != nil {
t.Error(err)
}
err = sqlitex.ExecTransient(conn, `CREATE TABLE foo (id integer primary key);`, nil)
if err != nil {
t.Error(err)
}
cancel()
pool.Put(conn)
if err := pool.Close(); err != nil {
t.Error(err)
}
if _, err := os.Stat(dbName + "-wal"); !errors.Is(err, os.ErrNotExist) {
t.Error("wal file should not exist after close")
}
}