Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
442aad69
Commit
442aad69
authored
Feb 22, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for busy handling.
parent
4b894bab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
2 deletions
+105
-2
busy_test.go
busy_test.go
+104
-0
sqlite_test.go
sqlite_test.go
+1
-1
trace.go
trace.go
+0
-1
No files found.
busy_test.go
0 → 100644
View file @
442aad69
package
sqlite_test
import
(
.
"github.com/gwenn/gosqlite"
"io/ioutil"
"os"
"testing"
"time"
)
/*
func TestInterrupt(t *testing.T) {
db := open(t)
defer db.Close()
db.CreateScalarFunction("interrupt", 0, nil, func(ctx *Context, nArg int) {
//db.Interrupt()
ctx.ResultText("ok")
}, nil)
var err error
var result string
err = db.OneValue("select interrupt()", &result)
if err == nil || err != ErrInterrupt {
t.Errorf("Expected interrupt but got %#v", err)
}
}
*/
func
openTwoConnSameDb
(
t
*
testing
.
T
)
(
*
os
.
File
,
*
Conn
,
*
Conn
)
{
f
,
err
:=
ioutil
.
TempFile
(
""
,
"gosqlite-test"
)
checkNoError
(
t
,
f
.
Close
(),
"couldn't close temp file: %s"
)
db1
,
err
:=
Open
(
f
.
Name
(),
OPEN_READWRITE
,
OPEN_CREATE
,
OPEN_FULLMUTEX
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
db2
,
err
:=
Open
(
f
.
Name
(),
OPEN_READWRITE
,
OPEN_CREATE
,
OPEN_FULLMUTEX
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
return
f
,
db1
,
db2
}
func
TestDefaultBusy
(
t
*
testing
.
T
)
{
f
,
db1
,
db2
:=
openTwoConnSameDb
(
t
)
defer
os
.
Remove
(
f
.
Name
())
defer
db1
.
Close
()
defer
db2
.
Close
()
checkNoError
(
t
,
db1
.
BeginTransaction
(
EXCLUSIVE
),
"couldn't begin transaction: %s"
)
defer
db1
.
Rollback
()
_
,
err
:=
db2
.
SchemaVersion
()
if
err
==
nil
{
t
.
Fatalf
(
"Expected lock but got %v"
,
err
)
}
if
se
,
ok
:=
err
.
(
*
StmtError
);
!
ok
||
se
.
Code
()
!=
ErrBusy
{
t
.
Fatalf
(
"Exepted lock but got %#v"
,
err
)
}
}
func
TestBusyTimeout
(
t
*
testing
.
T
)
{
f
,
db1
,
db2
:=
openTwoConnSameDb
(
t
)
defer
os
.
Remove
(
f
.
Name
())
defer
db1
.
Close
()
defer
db2
.
Close
()
checkNoError
(
t
,
db1
.
BeginTransaction
(
EXCLUSIVE
),
"couldn't begin transaction: %s"
)
//join := make(chan bool)
checkNoError
(
t
,
db2
.
BusyTimeout
(
500
),
"couldn't set busy timeout: %s"
)
go
func
()
{
time
.
Sleep
(
time
.
Millisecond
)
db1
.
Rollback
()
//join <- true
}()
_
,
err
:=
db2
.
SchemaVersion
()
checkNoError
(
t
,
err
,
"couldn't query schema version: %#v"
)
//<- join
}
func
TestBusyHandler
(
t
*
testing
.
T
)
{
f
,
db1
,
db2
:=
openTwoConnSameDb
(
t
)
defer
os
.
Remove
(
f
.
Name
())
defer
db1
.
Close
()
defer
db2
.
Close
()
//c := make(chan bool)
var
called
bool
err
:=
db2
.
BusyHandler
(
func
(
udp
interface
{},
count
int
)
bool
{
if
b
,
ok
:=
udp
.
(
*
bool
);
ok
{
*
b
=
true
}
//c <- true
return
true
},
&
called
)
checkNoError
(
t
,
db1
.
BeginTransaction
(
EXCLUSIVE
),
"couldn't begin transaction: %s"
)
go
func
()
{
time
.
Sleep
(
time
.
Millisecond
)
//_ = <- c
db1
.
Rollback
()
}()
_
,
err
=
db2
.
SchemaVersion
()
checkNoError
(
t
,
err
,
"couldn't query schema version: %#v"
)
if
!
called
{
t
.
Fatalf
(
"Busy handler not called!"
)
}
}
sqlite_test.go
View file @
442aad69
...
...
@@ -14,7 +14,7 @@ func checkNoError(t *testing.T, err error, format string) {
}
func
open
(
t
*
testing
.
T
)
*
Conn
{
db
,
err
:=
Open
(
""
,
OPEN_READWRITE
,
OPEN_CREATE
,
OPEN_FULLMUTEX
,
OPEN_URI
)
db
,
err
:=
Open
(
""
,
OPEN_READWRITE
,
OPEN_CREATE
,
OPEN_FULLMUTEX
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
if
db
==
nil
{
t
.
Fatal
(
"opened database is nil"
)
...
...
trace.go
View file @
442aad69
...
...
@@ -202,7 +202,6 @@ func goXBusy(udp unsafe.Pointer, count int) C.int {
}
// Register a callback to handle SQLITE_BUSY errors
// TODO NOT TESTED
// (See http://sqlite.org/c3ref/busy_handler.html)
func
(
c
*
Conn
)
BusyHandler
(
f
BusyHandler
,
udp
interface
{})
error
{
if
f
==
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment