Skip to content

tests: fix flaky WATCHed-key-expired EXEC test under Valgrind - #4441

Open
Xsidz wants to merge 1 commit into
valkey-io:unstablefrom
Xsidz:fix/watch-valgrind-timing
Open

tests: fix flaky WATCHed-key-expired EXEC test under Valgrind#4441
Xsidz wants to merge 1 commit into
valkey-io:unstablefrom
Xsidz:fix/watch-valgrind-timing

Conversation

@Xsidz

@Xsidz Xsidz commented Aug 16, 2026

Copy link
Copy Markdown

Summary

  • Scale the TTL and wait in the WATCHed key in another slot that expired aborts EXEC test when running under Valgrind.

Root cause

Under Valgrind the server processes commands 100–1000x slower than
normal. The test sets a key with a 50 ms TTL and immediately WATCHes
it. If Valgrind's overhead causes WATCH to be processed more than 50 ms
after SET, keyIsExpired() fires inside watchForKey() and marks the
key as "already expired when WATCHed" (wk->expired = 1).
isWatchedKeyExpired() then skips the key (if (wk->expired) continue
multi.c:457), so EXEC commits instead of aborting and the assertion
assert_equal {} $reply fails.

The same CI run that triggered issues #4435/#4436 also triggered this
failure three times consecutively on test-valgrind-test-cluster and
test-valgrind-no-malloc-usable-size-test-cluster.

Fix

Use $::valgrind (already available in the test framework) to scale
the TTL (50 ms → 5 s) and the wait (100 ms → 10 s) so that:

  1. The key has not expired by the time WATCH is processed, even under
    Valgrind.
  2. The key is definitely expired by the time EXEC runs.

Test plan

  • ./runtest-cluster --single tests/unit/cluster/misc.tcl passes locally (non-Valgrind)
  • Confirmed the Valgrind-specific path would keep the key alive across WATCH by construction (TTL 5 s >> Valgrind overhead)

Fixes #4407

Signed-off-by: Siddhesh Kabra siddhesh.kabraa@gmail.com

Under Valgrind the server processes commands 100–1000x slower than
normal.  The test sets a key with a 50 ms TTL and then immediately
WATCHes it.  If Valgrind's overhead causes the WATCH to be processed
more than 50 ms after the SET, keyIsExpired() fires inside
watchForKey() and marks the key as "already expired when WATCHed"
(wk->expired = 1).  isWatchedKeyExpired() then skips the key
(line 457: "if (wk->expired) continue"), so EXEC commits instead of
aborting, and the test fails.

Scale the TTL (50 ms → 5 s) and the wait (100 ms → 10 s) when running
under Valgrind so that the WATCH is always processed before the TTL
elapses and the wait is always long enough for expiry to occur before
EXEC.

Fixes valkey-io#4407

Signed-off-by: Siddhesh Kabra <siddhesh.kabraa@gmail.com>
Signed-off-by: Xsidz <siddhesh.kabraa@gmail.com>
Copilot AI lite review requested due to automatic review settings August 16, 2026 17:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 887fe298-d1e8-4e31-8177-76f6e0ce0d69

📥 Commits

Reviewing files that changed from the base of the PR and between 4669926 and c1490b2.

📒 Files selected for processing (1)
  • tests/unit/cluster/misc.tcl

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The WATCH expiration regression test now uses longer TTL and wait durations under Valgrind. Non-Valgrind runs retain the existing durations.

Changes

WATCH expiration regression test

Layer / File(s) Summary
Valgrind timing adjustment
tests/unit/cluster/misc.tcl
The test uses a 5000 ms TTL and 10000 ms wait under Valgrind. Other runs use 50 ms and 100 ms.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to c1490

This PR adjusts test timing for Valgrind environments without changing production behavior; no actionable merge-blocking risk remains.

Possibly related PRs

Suggested reviewers: enjoy-binbin

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the test fix and the Valgrind-specific flakiness it addresses.
Description check ✅ Passed The description explains the failure cause and the timing-based fix for the affected test.
Linked Issues check ✅ Passed The changes directly address issue #4407 by preventing the WATCH expiration test from racing under Valgrind.
Out of Scope Changes check ✅ Passed The pull request only changes timing values in the affected regression test and contains no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST-FAILURE] WATCHed key in another slot that expired aborts EXEC in tests/unit/cluster/misc.tcl

2 participants