Skip to content

Commit 1a87692

Browse files
committed
Tests.
1 parent 2640c9f commit 1a87692

File tree

4 files changed

+51
-35
lines changed

4 files changed

+51
-35
lines changed

func.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *Conn) CreateWindowFunction(name string, nArg int, flag FunctionFlag, fn
132132
if win, ok := agg.(WindowFunction); ok {
133133
return win
134134
}
135-
return windowFunc{agg, name}
135+
return agg
136136
}))
137137
}
138138
rc := res_t(c.call("sqlite3_create_window_function_go",
@@ -307,13 +307,3 @@ func (a *aggregateFunc) Close() error {
307307
a.stop()
308308
return nil
309309
}
310-
311-
type windowFunc struct {
312-
AggregateFunction
313-
name string
314-
}
315-
316-
func (w windowFunc) Inverse(ctx Context, arg ...Value) {
317-
// Implementing inverse allows certain queries that don't really need it to succeed.
318-
ctx.ResultError(util.ErrorString(w.name + ": may not be used as a window function"))
319-
}

internal/util/func.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ func ExportFuncVI[T0 i32](mod wazero.HostModuleBuilder, name string, fn func(con
2020
Export(name)
2121
}
2222

23-
type funcVII[T0, T1 i32] func(context.Context, api.Module, T0, T1)
24-
25-
func (fn funcVII[T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) {
26-
_ = stack[1] // prevent bounds check on every slice access
27-
fn(ctx, mod, T0(stack[0]), T1(stack[1]))
28-
}
29-
30-
func ExportFuncVII[T0, T1 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1)) {
31-
mod.NewFunctionBuilder().
32-
WithGoModuleFunction(funcVII[T0, T1](fn),
33-
[]api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, nil).
34-
Export(name)
35-
}
36-
3723
type funcVIII[T0, T1, T2 i32] func(context.Context, api.Module, T0, T1, T2)
3824

3925
func (fn funcVIII[T0, T1, T2]) Call(ctx context.Context, mod api.Module, stack []uint64) {

tests/conn_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/ncruces/go-sqlite3"
1313
_ "github.com/ncruces/go-sqlite3/embed"
1414
_ "github.com/ncruces/go-sqlite3/internal/testcfg"
15-
_ "github.com/ncruces/go-sqlite3/vfs/memdb"
15+
"github.com/ncruces/go-sqlite3/vfs/memdb"
1616
)
1717

1818
func TestConn_Open_dir(t *testing.T) {
@@ -112,6 +112,48 @@ func TestConn_Close_BUSY(t *testing.T) {
112112
}
113113
}
114114

115+
func TestConn_BusyHandler(t *testing.T) {
116+
t.Parallel()
117+
118+
dsn := memdb.TestDB(t)
119+
120+
db1, err := sqlite3.Open(dsn)
121+
if err != nil {
122+
t.Fatal(err)
123+
}
124+
defer db1.Close()
125+
126+
db2, err := sqlite3.Open(dsn)
127+
if err != nil {
128+
t.Fatal(err)
129+
}
130+
defer db2.Close()
131+
132+
var called bool
133+
err = db2.BusyHandler(func(ctx context.Context, count int) (retry bool) {
134+
called = true
135+
return count < 1
136+
})
137+
if err != nil {
138+
t.Fatal(err)
139+
}
140+
141+
tx, err := db1.BeginExclusive()
142+
if err != nil {
143+
t.Fatal(err)
144+
}
145+
defer tx.End(&err)
146+
147+
_, err = db2.BeginExclusive()
148+
if !errors.Is(err, sqlite3.BUSY) {
149+
t.Errorf("got %v, want sqlite3.BUSY", err)
150+
}
151+
152+
if !called {
153+
t.Error("busy handler not called")
154+
}
155+
}
156+
115157
func TestConn_SetInterrupt(t *testing.T) {
116158
t.Parallel()
117159

vfs/memdb/memdb.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,16 @@ func (memVFS) FullPathname(name string) (string, error) {
7676
type memDB struct {
7777
name string
7878

79+
// +checklocks:lockMtx
80+
waiter *sync.Cond
7981
// +checklocks:dataMtx
8082
data []*[sectorSize]byte
81-
// +checklocks:dataMtx
82-
size int64
83-
84-
// +checklocks:memoryMtx
85-
refs int32
8683

87-
shared int32 // +checklocks:lockMtx
88-
pending bool // +checklocks:lockMtx
89-
reserved bool // +checklocks:lockMtx
90-
waiter *sync.Cond // +checklocks:lockMtx
84+
size int64 // +checklocks:dataMtx
85+
refs int32 // +checklocks:memoryMtx
86+
shared int32 // +checklocks:lockMtx
87+
pending bool // +checklocks:lockMtx
88+
reserved bool // +checklocks:lockMtx
9189

9290
lockMtx sync.Mutex
9391
dataMtx sync.RWMutex

0 commit comments

Comments
 (0)