From fb140a1bff5a4fc3082e362f4b57030625193115 Mon Sep 17 00:00:00 2001 From: ny0312 <49037844+ny0312@users.noreply.github.com> Date: Sat, 12 Jun 2021 22:42:20 -0700 Subject: [PATCH] Fix flaky test case for absolute TTL replication (#9069) The root cause is that one test (`5 keys in, 5 keys out`) is leaking a volatile key that can expire while another later test(`All TTL in commands are propagated as absolute timestamp in replication stream`) is running. Such leaked expiration injects an unexpected `DEL` command into the replication command during the later test, causing it to fail. The fixes are two fold: 1. Plug the leak in the first test. 2. Add FLUSHALL to the later test, to avoid future interference from other tests. --- src/expire.c | 2 +- tests/unit/expire.tcl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/expire.c b/src/expire.c index 8996ae57e..91798b527 100644 --- a/src/expire.c +++ b/src/expire.c @@ -570,7 +570,7 @@ void pexpireatCommand(client *c) { expireGenericCommand(c,0,UNIT_MILLISECONDS); } -/* Implements TTL, PTTL and EXPIRETIME */ +/* Implements TTL, PTTL, EXPIRETIME and PEXPIRETIME */ void ttlGenericCommand(client *c, int output_ms, int output_abs) { long long expire, ttl = -1; diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index 5293d90fa..d3c9d63c5 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -221,8 +221,9 @@ start_server {tags {"expire"}} { r set e c r set s c r set foo b - lsort [r keys *] - } {a e foo s t} + assert_equal [lsort [r keys *]] {a e foo s t} + r del a ; # Do not leak volatile keys to other tests + } test {EXPIRE with empty string as TTL should report an error} { r set foo bar @@ -433,6 +434,7 @@ start_server {tags {"expire"}} { # stream, which is as absolute timestamps. # See: https://github.com/redis/redis/issues/8433 + r flushall ; # Clean up keyspace to avoid interference by keys from other tests set repl [attach_to_replication_stream] # SET commands r set foo1 bar ex 200