simplify COPY Preserves TTLs hashexpire test (#2495)

Simplifies a test case seen to be flaky.

fixes: https://github.com/valkey-io/valkey/issues/2482

Signed-off-by: Ran Shidlansik <ranshid@amazon.com>
This commit is contained in:
Ran Shidlansik 2025-08-17 12:53:41 +03:00 committed by GitHub
parent f36cc20836
commit e364c57e3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 55 deletions

View File

@ -1419,69 +1419,25 @@ start_server {tags {"hashexpire"}} {
test {COPY Preserves TTLs} {
r flushall
r DEBUG SET-ACTIVE-EXPIRE 0
# Create hash with fields
r HSET myhash{t} f1 v1 f3 v3 f4 v4
# Set TTL on f1 only
r HEXPIRE myhash{t} 200 FIELDS 1 f1
r HEXPIRE myhash{t} 2 FIELDS 1 f3
# Verify initial TTL state
set mem_before [r MEMORY USAGE myhash{t}]
assert_equal "v1 v3 v4" [r HMGET myhash{t} f1 f3 f4]
assert_morethan [r HTTL myhash{t} FIELDS 1 f1] 100
assert_morethan [r HTTL myhash{t} FIELDS 1 f3] 0
assert_equal -1 [r HTTL myhash{t} FIELDS 1 f4]
assert_equal 3 [r HLEN myhash{t}]
assert_equal 1 [get_keys r]
assert_equal 1 [get_keys_with_volatile_items r]
r HEXPIRE myhash{t} 2000 FIELDS 1 f1
r HEXPIRE myhash{t} 5000 FIELDS 1 f3
# Copy hash to new key
r copy myhash{t} newhash1{t}
r copy myhash{t} nwhash{t}
# Verify myhash{t} is the same
# Verify initial TTL state
assert_equal [r MEMORY USAGE myhash{t}] [r MEMORY USAGE nwhash{t}]
assert_equal "v1 v3 v4" [r HMGET myhash{t} f1 f3 f4]
assert_morethan [r HTTL myhash{t} FIELDS 1 f1] 100
assert_morethan [r HTTL myhash{t} FIELDS 1 f3] 0
assert_equal -1 [r HTTL myhash{t} FIELDS 1 f4]
assert_equal 3 [r HLEN myhash{t}]
# Verify new hash got same values
set mem_after [r MEMORY USAGE myhash{t}]
assert_equal "v1 v3 v4" [r HMGET myhash{t} f1 f3 f4]
assert_morethan [r HTTL newhash1{t} FIELDS 1 f1] 100
assert_morethan [r HTTL newhash1{t} FIELDS 1 f3] 0
assert_equal -1 [r HTTL newhash1{t} FIELDS 1 f4]
assert_equal 3 [r HLEN newhash1{t}]
assert_equal 2 [get_keys r]
assert_equal 2 [get_keys_with_volatile_items r]
assert_equal $mem_before $mem_after
# Modify TTL in original hash
r HEXPIRE myhash{t} 5 FIELDS 1 f3
# Wait for original TTL to expire in copy
after 2000
assert_equal "v1 {}" [r HMGET newhash1{t} f1 f3]
assert_equal "v1 v3" [r HMGET myhash{t} f1 f3]
r HSETEX myhash{t} EX 2 FIELDS 1 f3 v3
# Create second copy
r copy myhash{t} newhash2{t}
# Modify TTL in second copy
r HEXPIRE newhash2{t} 500 FIELDS 1 f3
# Wait for original hash TTL to expire
after 2000
assert_equal "v1 {}" [r HMGET myhash{t} f1 f3]
assert_equal "v1 v3" [r HMGET newhash2{t} f1 f3]
# Re-enable active expiry
r DEBUG SET-ACTIVE-EXPIRE 1
} {OK} {needs:debug}
assert_equal "v1 v3 v4" [r HMGET nwhash{t} f1 f3 f4]
assert_equal [r HEXPIRETIME myhash{t} FIELDS 1 f1] [r HEXPIRETIME nwhash{t} FIELDS 1 f1]
assert_equal [r HEXPIRETIME myhash{t} FIELDS 1 f2] [r HEXPIRETIME nwhash{t} FIELDS 1 f2]
assert_equal [r HEXPIRETIME myhash{t} FIELDS 1 f3] [r HEXPIRETIME nwhash{t} FIELDS 1 f3]
assert_equal [r HEXPIRETIME myhash{t} FIELDS 1 f4] [r HEXPIRETIME nwhash{t} FIELDS 1 f4]
}
test {Hash Encoding Transitions with TTL - Add TTL to Existing Fields} {
r flushall