forked from mirror/go-sqlite3
use file instead of memory for TestShortTimeout
This commit is contained in:
parent
05548ff555
commit
68bcba68d9
|
@ -111,14 +111,17 @@ func initDatabase(t *testing.T, db *sql.DB, rowCount int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShortTimeout(t *testing.T) {
|
func TestShortTimeout(t *testing.T) {
|
||||||
db, err := sql.Open("sqlite3", "file::memory:?mode=memory&cache=shared")
|
srcTempFilename := TempFilename(t)
|
||||||
|
defer os.Remove(srcTempFilename)
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", srcTempFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
initDatabase(t, db, 10000)
|
initDatabase(t, db, 100)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Microsecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
query := `SELECT key1, key_id, key2, key3, key4, key5, key6, data
|
query := `SELECT key1, key_id, key2, key3, key4, key5, key6, data
|
||||||
FROM test_table
|
FROM test_table
|
||||||
|
@ -127,16 +130,8 @@ func TestShortTimeout(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
if ctx.Err() != nil && context.DeadlineExceeded != ctx.Err() {
|
||||||
for rows.Next() {
|
t.Fatalf("%v", ctx.Err())
|
||||||
var key1, keyid, key2, key3, key4, key5, key6 string
|
|
||||||
var data []byte
|
|
||||||
err = rows.Scan(&key1, &keyid, &key2, &key3, &key4, &key5, &key6, &data)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if context.DeadlineExceeded != ctx.Err() {
|
|
||||||
t.Fatal(ctx.Err())
|
|
||||||
}
|
}
|
||||||
|
rows.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue