mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
fix TestExpireAt
This commit is contained in:
@@ -191,7 +191,6 @@ func TestExpireAt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExpiredTime(t *testing.T) {
|
func TestExpiredTime(t *testing.T) {
|
||||||
//测试ExpireTime
|
|
||||||
testDB.Flush()
|
testDB.Flush()
|
||||||
key := utils.RandString(10)
|
key := utils.RandString(10)
|
||||||
value := utils.RandString(10)
|
value := utils.RandString(10)
|
||||||
@@ -204,6 +203,7 @@ func TestExpiredTime(t *testing.T) {
|
|||||||
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
|
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
|
||||||
asserts.AssertIntReply(t, result, -1)
|
asserts.AssertIntReply(t, result, -1)
|
||||||
|
|
||||||
|
estimateExpireTimestamp := time.Now().Add(2 * time.Second).Unix() // actually expiration may be >= estimateExpireTimestamp
|
||||||
testDB.Exec(nil, utils.ToCmdLine("EXPIRE", key, "2"))
|
testDB.Exec(nil, utils.ToCmdLine("EXPIRE", key, "2"))
|
||||||
//tt := time.Now()
|
//tt := time.Now()
|
||||||
result = testDB.Exec(nil, utils.ToCmdLine("ttl", key))
|
result = testDB.Exec(nil, utils.ToCmdLine("ttl", key))
|
||||||
@@ -217,25 +217,23 @@ func TestExpiredTime(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result = testDB.Exec(nil, utils.ToCmdLine("EXPIRETIME", key))
|
result = testDB.Exec(nil, utils.ToCmdLine("EXPIRETIME", key))
|
||||||
asserts.AssertIntReply(t, result, int(time.Now().Add(2*time.Second).Unix()))
|
|
||||||
intResult, ok = result.(*protocol.IntReply)
|
intResult, ok = result.(*protocol.IntReply)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("expected int protocol, actually %s", result.ToBytes())
|
t.Errorf("expected int protocol, actually %s", result.ToBytes())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if intResult.Code <= 0 {
|
if intResult.Code < estimateExpireTimestamp {
|
||||||
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
|
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
|
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
|
||||||
asserts.AssertIntReply(t, result, int(time.Now().Add(2*time.Second).UnixMilli()))
|
|
||||||
intResult, ok = result.(*protocol.IntReply)
|
intResult, ok = result.(*protocol.IntReply)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("expected int protocol, actually %s", result.ToBytes())
|
t.Errorf("expected int protocol, actually %s", result.ToBytes())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if intResult.Code <= 0 {
|
if intResult.Code < estimateExpireTimestamp*1000 {
|
||||||
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
|
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user