Skip to content

Commit 07b39a0

Browse files
committed
Add TestStress
1 parent 3db806a commit 07b39a0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sqlite3_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,40 @@ func TestQueryer(t *testing.T) {
700700
}
701701
}
702702
}
703+
704+
func TestStress(t *testing.T) {
705+
tempFilename := TempFilename()
706+
db, err := sql.Open("sqlite3", tempFilename)
707+
if err != nil {
708+
t.Fatal("Failed to open database:", err)
709+
}
710+
db.Exec("CREATE TABLE foo (id int);")
711+
db.Exec("INSERT INTO foo VALUES(1);")
712+
db.Exec("INSERT INTO foo VALUES(2);")
713+
db.Close()
714+
715+
for i := 0; i < 10000; i++ {
716+
db, err := sql.Open("sqlite3", tempFilename)
717+
if err != nil {
718+
t.Fatal("Failed to open database:", err)
719+
}
720+
721+
for j := 0; j < 3; j++ {
722+
rows, err := db.Query("select * from foo where id=1;")
723+
if err != nil {
724+
t.Error("Failed to call db.Query:", err)
725+
}
726+
for rows.Next() {
727+
var i int
728+
if err := rows.Scan(&i); err != nil {
729+
t.Errorf("Scan failed: %v\n", err)
730+
}
731+
}
732+
if err := rows.Err(); err != nil {
733+
t.Errorf("Post-scan failed: %v\n", err)
734+
}
735+
rows.Close()
736+
}
737+
db.Close()
738+
}
739+
}

0 commit comments

Comments
 (0)