Skip to content

Commit

Permalink
fix TestExpireAt
Browse files Browse the repository at this point in the history
  • Loading branch information
HDT3213 committed Jul 29, 2023
1 parent 1034641 commit 164a0df
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions database/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func TestExpireAt(t *testing.T) {
}

func TestExpiredTime(t *testing.T) {
//测试ExpireTime
testDB.Flush()
key := utils.RandString(10)
value := utils.RandString(10)
Expand All @@ -204,6 +203,7 @@ func TestExpiredTime(t *testing.T) {
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
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"))
//tt := time.Now()
result = testDB.Exec(nil, utils.ToCmdLine("ttl", key))
Expand All @@ -217,25 +217,23 @@ func TestExpiredTime(t *testing.T) {
return
}
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)
if !ok {
t.Errorf("expected int protocol, actually %s", result.ToBytes())
return
}
if intResult.Code <= 0 {
if intResult.Code < estimateExpireTimestamp {
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
return
}

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)
if !ok {
t.Errorf("expected int protocol, actually %s", result.ToBytes())
return
}
if intResult.Code <= 0 {
if intResult.Code < estimateExpireTimestamp*1000 {
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
return
}
Expand Down

0 comments on commit 164a0df

Please sign in to comment.