Add a write-cache to the database interface options

This commit is contained in:
Daniel 2020-10-11 14:27:54 +02:00
parent d4bb5ae522
commit abaf5ee879
7 changed files with 472 additions and 102 deletions

View file

@ -22,6 +22,24 @@ import (
_ "github.com/safing/portbase/database/storage/hashmap"
)
func TestMain(m *testing.M) {
testDir, err := ioutil.TempDir("", "portbase-database-testing-")
if err != nil {
panic(err)
}
err = InitializeWithPath(testDir)
if err != nil {
panic(err)
}
exitCode := m.Run()
os.RemoveAll(testDir) // clean up
os.Exit(exitCode)
}
func makeKey(dbName, key string) string {
return fmt.Sprintf("%s:%s", dbName, key)
}
@ -220,23 +238,19 @@ func testDatabase(t *testing.T, storageType string, shadowDelete bool) { //nolin
func TestDatabaseSystem(t *testing.T) {
// panic after 10 seconds, to check for locks
go func() {
time.Sleep(10 * time.Second)
fmt.Println("===== TAKING TOO LONG - PRINTING STACK TRACES =====")
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
os.Exit(1)
finished := make(chan struct{})
defer func() {
close(finished)
}()
go func() {
select {
case <-finished:
case <-time.After(10 * time.Second):
fmt.Println("===== TAKING TOO LONG - PRINTING STACK TRACES =====")
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
os.Exit(1)
}
}()
testDir, err := ioutil.TempDir("", "portbase-database-testing-")
if err != nil {
t.Fatal(err)
}
err = InitializeWithPath(testDir)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testDir) // clean up
for _, shadowDelete := range []bool{false, true} {
testDatabase(t, "bbolt", shadowDelete)
@ -246,7 +260,7 @@ func TestDatabaseSystem(t *testing.T) {
// TODO: Fix badger tests
}
err = MaintainRecordStates(context.TODO())
err := MaintainRecordStates(context.TODO())
if err != nil {
t.Fatal(err)
}