Skip to content

Commit 7ba7ac4

Browse files
authored
Merge pull request #1696 from monkey92t/test_error
fix test error
2 parents a9989a3 + e839f8e commit 7ba7ac4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

commands_test.go

Lines changed: 10 additions & 3 deletions
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() {
@@ -1458,7 +1465,7 @@ var _ = Describe("Commands", func() {
14581465
})
14591466

14601467
It("should SetEX", func() {
1461-
err := client.SetEX(ctx, "key", "hello", 100*time.Millisecond).Err()
1468+
err := client.SetEX(ctx, "key", "hello", 1*time.Second).Err()
14621469
Expect(err).NotTo(HaveOccurred())
14631470

14641471
val, err := client.Get(ctx, "key").Result()
@@ -1467,7 +1474,7 @@ var _ = Describe("Commands", func() {
14671474

14681475
Eventually(func() error {
14691476
return client.Get(ctx, "foo").Err()
1470-
}, "1s", "100ms").Should(Equal(redis.Nil))
1477+
}, "2s", "100ms").Should(Equal(redis.Nil))
14711478
})
14721479

14731480
It("should SetNX", func() {

0 commit comments

Comments
 (0)