fix issue in unit test case for gkvdb

This commit is contained in:
John
2019-08-26 22:54:59 +08:00
parent d3a2bef9ba
commit d67975249c
2 changed files with 22 additions and 23 deletions

View File

@ -25,13 +25,16 @@ import (
func Test_New(t *testing.T) {
gtest.Case(t, func() {
path := "/tmp/gkvdb/" + gconv.String(gtime.Nanosecond())
name := gconv.String(gtime.Nanosecond())
path := "/tmp/gkvdb/" + name
key := []byte("key")
value := []byte("value")
db := gkvdb.Instance()
db.SetPath(path)
err := db.Set(key, value)
db := gkvdb.Instance(name)
err := db.SetPath(path)
gtest.Assert(err, nil)
err = db.Set(key, value)
gtest.Assert(err, nil)
gtest.Assert(db.Get(key), value)
@ -42,26 +45,31 @@ func Test_New(t *testing.T) {
func Test_Set(t *testing.T) {
gtest.Case(t, func() {
path := "/tmp/gkvdb/" + gconv.String(gtime.Nanosecond())
name := gconv.String(gtime.Nanosecond())
path := "/tmp/gkvdb/" + name
key := []byte("key")
value := []byte("value")
db := gkvdb.Instance()
db.SetPath(path)
err := db.Set(key, value, 100*time.Millisecond)
db := gkvdb.Instance(name)
err := db.SetPath(path)
gtest.Assert(err, nil)
err = db.Set(key, value, 1000*time.Millisecond)
gtest.Assert(err, nil)
gtest.Assert(db.Get(key), value)
time.Sleep(200 * time.Millisecond)
time.Sleep(1500 * time.Millisecond)
gtest.Assert(db.Get(key), nil)
})
}
func Test_Iterate(t *testing.T) {
gtest.Case(t, func() {
path := "/tmp/gkvdb/" + gconv.String(gtime.Nanosecond())
db := gkvdb.Instance()
db.SetPath(path)
name := gconv.String(gtime.Nanosecond())
path := "/tmp/gkvdb/" + name
db := gkvdb.Instance(name)
err := db.SetPath(path)
gtest.Assert(err, nil)
strArray := garray.NewSortedStringArray()
strArrayReverse := garray.NewSortedStringArrayComparator(func(a, b string) int {