mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
add AppendFsync
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/aof"
|
||||
"github.com/hdt3213/godis/config"
|
||||
"github.com/hdt3213/godis/lib/utils"
|
||||
"github.com/hdt3213/godis/redis/connection"
|
||||
"github.com/hdt3213/godis/redis/protocol/asserts"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestLoadRDB(t *testing.T) {
|
||||
@@ -38,3 +41,40 @@ func TestLoadRDB(t *testing.T) {
|
||||
result = rdbDB.Exec(conn, utils.ToCmdLine("Get", "str"))
|
||||
asserts.AssertNullBulk(t, result)
|
||||
}
|
||||
|
||||
func TestServerFsyncAlways(t *testing.T) {
|
||||
aofFile, err := ioutil.TempFile("", "*.aof")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
config.Properties.AppendOnly = true
|
||||
config.Properties.AppendFilename = aofFile.Name()
|
||||
config.Properties.AppendFsync = aof.FsyncAlways
|
||||
server := NewStandaloneServer()
|
||||
conn := connection.NewFakeConn()
|
||||
ret := server.Exec(conn, utils.ToCmdLine("set", "1", "1"))
|
||||
asserts.AssertNotError(t, ret)
|
||||
reader := NewStandaloneServer()
|
||||
ret = reader.Exec(conn, utils.ToCmdLine("get", "1"))
|
||||
asserts.AssertBulkReply(t, ret, "1")
|
||||
}
|
||||
|
||||
func TestServerFsyncEverySec(t *testing.T) {
|
||||
aofFile, err := ioutil.TempFile("", "*.aof")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
config.Properties.AppendOnly = true
|
||||
config.Properties.AppendFilename = aofFile.Name()
|
||||
config.Properties.AppendFsync = aof.FsyncEverySec
|
||||
server := NewStandaloneServer()
|
||||
conn := connection.NewFakeConn()
|
||||
ret := server.Exec(conn, utils.ToCmdLine("set", "1", "1"))
|
||||
asserts.AssertNotError(t, ret)
|
||||
time.Sleep(1500 * time.Millisecond)
|
||||
reader := NewStandaloneServer()
|
||||
ret = reader.Exec(conn, utils.ToCmdLine("get", "1"))
|
||||
asserts.AssertBulkReply(t, ret, "1")
|
||||
}
|
||||
|
Reference in New Issue
Block a user