GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — test: Fix flaky touch assertions comparing OBJECT IDLETIME to exactly 0 by renechoi · Pull Request #4649 · redis/jedis Conversation
|
| Class | Per-run result |
|---|---|
SentinelAllKindOfValuesCommandsIT |
45 run, 0 failures, 3 skipped |
ClusterAllKindOfValuesCommandsTest |
45 run, 0 failures, 3 skipped |
RedisClientAllKindOfValuesCommandsTest |
45 run, 0 failures, 3 skipped |
AllKindOfValuesCommandsTest (legacy) |
54 run, 0 failures, 3 skipped |
432 run, 0 failures, 0 errors, 27 skipped in total across the RESP parameterizations, BUILD SUCCESS.
dumpAndRestore has the same shape a bit further down — RESTORE ... IDLETIME 1000 followed by assertEquals(1000, objectIdletime(...)) — in both the unified base and the legacy copy. It is exposed to the same tick, though I have not seen it reported. I left it alone to keep this focused on #4591; happy to fold it in here or send it separately, whichever you prefer.
Fixes #4591
Note
Low Risk
Test-only assertion and import changes; no library or runtime behavior is modified.
Overview
Fixes intermittent CI failures in touch integration tests (#4591) by aligning assertions with Redis’s one-second LRU clock for OBJECT IDLETIME.
After TOUCH, tests no longer require idle time to be exactly 0; they assert <= 1 via Hamcrest lessThanOrEqualTo, so a clock tick between TOUCH and OBJECT IDLETIME does not fail the run. The same change is applied across the unified base, cluster override, and legacy AllKindOfValuesCommandsTest (string and binary keys).
The legacy jedis test class also switches several Hamcrest matchers to static imports (e.g. hasItem, greaterThanOrEqualTo) instead of Matchers.*.
Reviewed by Cursor Bugbot for commit 5008f32. Bugbot is set up for automated code reviews on this repo. Configure here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
OBJECT IDLETIME is derived from the LRU clock, whose resolution is one second. TOUCH stamps the key with the current clock value and the read then subtracts two second-granular values, so a tick landing between the two commands yields 1 rather than 0 regardless of how closely they are issued. Assert <= 1 instead, matching what ObjectCommandsTest already does for the same command. The reported failure is the binary half of the unified test, but the same assertion exists in the String half, in the cluster override and in both halves of the legacy copy, so all five are updated. Fixes redis#4591
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I looked at this from the completeness and coverage angle, and checked the OBJECT IDLETIME behaviour locally against Redis 8.0.2.
The root cause description matches what the server does: OBJECT IDLETIME is derived from the cached LRU clock (server.lruclock, refreshed in serverCron) at a one second resolution, so a tick landing between TOUCH and the read reports 1. lessThanOrEqualTo(1L) is also the tightest bound that stays deterministic here, and it is consistent with the range-matcher style already used by ObjectCommandsTest#objectIdletime and CommandObjectsServerManagementCommandsTest#testObjectIdletime.
Completeness: I went through every objectIdletime usage in the test tree, and all five brittle exact-zero assertions are covered here.
commands/jedis/AllKindOfValuesCommandsTest#touch (String + binary)commands/unified/AllKindOfValuesCommandsTestBase#touch (String + binary)commands/unified/cluster/ClusterAllKindOfValuesCommandsTest#touch (String only; that override has no binary section)The remaining callers (ObjectCommandsTest, CommandObjectsServerManagementCommandsTest, and the mocked tests) already assert ranges or mock the reply, so nothing equivalent is left behind.
One observation that is orthogonal to the flake, but relevant to what the test claims to verify: the assertion does not distinguish a touched key from an untouched one. Each key is SET immediately before, so its idle time is already 0 by the time TOUCH runs. Measured on 8.0.2, SET foo1 bar1 followed by OBJECT IDLETIME foo1 as two separate round trips returned 0 in 3000/3000 iterations, so the assertion passes just as well with the touch() call deleted. That was equally true of the old assertEquals(0L, ...), so this PR loses no coverage. It only means touch() exercises the reply value of TOUCH but not its effect on idle time.
Covering the effect would need a real idle window before the TOUCH. The cheapest deterministic shape I could confirm on 8.0.2:
SET foo1 bar1
(wait ~2s)
OBJECT IDLETIME foo1 -> 2 (assert >= 1)
TOUCH foo1
OBJECT IDLETIME foo1 -> 0 (assert <= 1)
The cost is a two second sleep in the suite, which may not be a trade worth making in this test. Would you prefer to keep touch() about the reply values only and cover the reset separately in ObjectCommandsTest, or is a sleep acceptable here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks, that completeness pass matches what I found: the same five exact-zero assertions, and the remaining On the second point, I agree with the observation and would rather not act on it in this PR. You are right that the assertion cannot tell a touched key from an untouched one. It is visible in the test without needing a server: What makes me want to keep it out of here is the cost, which multiplies more than it looks. The assertions sit in parameterized classes, so a 2 s sleep at each of the five sites is executed 16 times in a full build:
That is a little over half a minute of pure waiting added to the suite to assert one property, and it buys a test whose determinism depends on a timing margin, which is the category of thing this PR is trying to remove. If the reset behaviour is worth covering, I would rather it be its own test that pays the sleep once, and I do not think it can extend an existing one: So my preference is to keep |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@renechoi
@renechoi @kdelay 2s per test run is an expensive one, and I think this is better validated in server-side tests. From a client perspective, validating the response of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 5008f32fdd
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| assertEquals(1, jedis.touch("foo1")); | ||
| assertEquals(0L, jedis.objectIdletime("foo1").longValue()); | ||
| assertThat(jedis.objectIdletime("foo1"), lessThanOrEqualTo(1L)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Raise the idle-time tolerance above one second
For Redis-backed runs where the JVM or test host is paused for more than a second after TOUCH (for example under GC or loaded CI/sentinel/cluster scheduling), OBJECT IDLETIME can legitimately advance to 2+ before this read, so this still leaves the flake in place; ObjectCommandsTest.objectIdletime already allows up to 10 seconds for the same command. Please use that wider bounded tolerance for these updated TOUCH assertions rather than <= 1.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks, that settles the sleep question for me. On the automated suggestion above, to widen the bound from 1 s to 10 s: I would rather keep
If a value above 1 ever does turn up in CI, widening is a one-line follow-up with an actual data point behind it. Say the word if you would rather not revisit it and I will change it now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Let's keep it to 1 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks for the quick review and the merge, and for the import cleanup on the branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
test: Sporadic test failuresAllKindOfValuesCommandsTestBase.touch:399 — expected <0> but was <1>
There was an error while loading. Please reload this page.