Skip to content

Commit e722f52

Browse files
committed
fix "should Object" test error
Signed-off-by: monkey <[email protected]>
1 parent f63e0d6 commit e722f52

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

commands_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ var _ = Describe("Commands", func() {
457457
})
458458

459459
It("should Object", func() {
460+
start := time.Now()
460461
set := client.Set(ctx, "key", "hello", 0)
461462
Expect(set.Err()).NotTo(HaveOccurred())
462463
Expect(set.Val()).To(Equal("OK"))
@@ -470,7 +471,13 @@ var _ = Describe("Commands", func() {
470471

471472
idleTime := client.ObjectIdleTime(ctx, "key")
472473
Expect(idleTime.Err()).NotTo(HaveOccurred())
473-
Expect(idleTime.Val()).To(Equal(time.Duration(0)))
474+
475+
//Redis returned milliseconds/1000, which may cause ObjectIdleTime to be at a critical value,
476+
//should be +1s to deal with the critical value problem.
477+
//if too much time (>1s) is used during command execution, it may also cause the test to fail.
478+
//so the ObjectIdleTime result should be <=now-start+1s
479+
//link: https://github.com/redis/redis/blob/5b48d900498c85bbf4772c1d466c214439888115/src/object.c#L1265-L1272
480+
Expect(idleTime.Val()).To(BeNumerically("<=", time.Now().Sub(start) + time.Second))
474481
})
475482

476483
It("should Persist", func() {

0 commit comments

Comments
 (0)