Skip to content

Deflake COPY Preserves TTLs test under libc malloc - #4785

Merged
rainsupreme merged 3 commits into
valkey-io:unstablefrom
chky1386:deflake-hashexpire-copy-memory
Nov 9, 2026
Merged

rainsupreme merged 3 commits into
valkey-io:unstablefrom
chky1386:deflake-hashexpire-copy-memory

Conversation

@chky1386

@chky1386 chky1386 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4149.

The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

This matches the RESTORE variant of the neighbouring test: it asserts that the encoding is preserved and that memory is within ±16 bytes. It's a test-only change.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by ±16 bytes, across both encodings. unit/hashexpire passes on jemalloc and libc builds.

This PR is co-authored with Claude Opus 5.5.

The test compared MEMORY USAGE of the source hash and its COPY for exact
equality. COPY builds the new object from fresh allocations while the
source was grown with realloc, so with libc malloc (used by the sanitizer
builds) the usable size of the allocations can differ by one 16-byte
chunk in either direction, for both listpack and hashtable encodings.

Assert that the encoding is preserved and that memory stays within 16
bytes, matching what the RESTORE variant of the same test already does.

Fixes valkey-io#4149

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SS5jg1cBwVxVEMzNn6J7e

Signed-off-by: Roy Chen <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a5c3bca2-a8cc-4002-87c0-e7de0021887a

📥 Commits

Reviewing files that changed from the base of the PR and between 5992fa2 and d36710f.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 380b1592-6f70-4934-8955-d22654b78c2c

📥 Commits

Reviewing files that changed from the base of the PR and between dca022f and 5992fa2.

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

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The COPY TTL-preservation test now checks that the copied hash retains the source encoding. It replaces exact memory-usage equality with a comparison that allows a difference of up to 16 bytes.

Changes

COPY TTL test

Layer / File(s) Summary
COPY test assertions
tests/unit/hashexpire.tcl
The test checks that the copied hash has the same encoding as the source and that their memory usage differs by no more than 16 bytes.

Priority: ⬇️ Low

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

Severity of issue fixed: Low

Suggested reviewers: ranshid

Merge Risk: ⚪ Minimal · up to 5992f

This test-only change addresses the reported allocator-related failure and preserves the other COPY assertions. No merge-blocking risk remains.

Architecture Summary

Architecture risk: 🔵 Low · up to 5992f

The change affects 1 system.

Changed systems: tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in tests/unit/hashexpire.tcl: The COPY test adds an encoding equality check and compares copied memory usage with the source within ±16 bytes, replacing the exact memory equality check.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: preventing the COPY TTL-preservation test from failing under libc malloc.
Description check ✅ Passed The description directly explains the libc malloc failure, the ±16-byte tolerance change, and the test-only scope.
Linked Issues check ✅ Passed The change addresses #4149 in tests/unit/hashexpire.tcl. It replaces the failing exact MEMORY USAGE comparison with a ±16-byte range check. It also verifies that OBJECT ENCODING remains equal an…
Out of Scope Changes check ✅ Passed The diff changes only the COPY Preserves TTLs test in tests/unit/hashexpire.tcl. The added assertions and tolerance directly support the objective in #4149. No unrelated source, API, or test behav…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…

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.

@chky1386
chky1386 marked this pull request as ready for review September 27, 2026 08:05
@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.61%. Comparing base (7fe7ca4) to head (d36710f).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4785      +/-   ##
============================================
- Coverage     80.61%   80.61%   -0.01%     
============================================
  Files           194      194              
  Lines        101189   101189              
============================================
- Hits          81571    81570       -1     
- Misses        19618    19619       +1     

see 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@madolson
madolson requested a review from rainsupreme October 30, 2026 03:01

@rainsupreme rainsupreme 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.

LGTM. Confirmed on a MALLOC=libc build: in a 20000-iteration loop of this test body, the old exact check failed 18 times (the copy was 16 bytes larger or smaller) and the new check did not fail.

One fix to the description before merge, since it becomes the commit message: the copy and source differ not because one was realloc'd, but because glibc's usable size depends on free-list state (a leftover under its 32-byte minimum chunk is handed out with the allocation).

Comment thread tests/unit/hashexpire.tcl
# With libc malloc, MEMORY USAGE of the copy can differ by an allocator chunk.
assert_equal [r OBJECT ENCODING myhash{t}] [r OBJECT ENCODING nwhash{t}]
set mem_src [r MEMORY USAGE myhash{t}]
assert_range [r MEMORY USAGE nwhash{t}] [expr {$mem_src - 16}] [expr {$mem_src + 16}]

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.

nit: Is one 16-byte step the worst case for both encodings? In listpack there is one realloc'd buffer, but if hashtable encoding has several grown allocations the steps add up and +/-16 can still flake. The chances are super low though.

@rainsupreme
rainsupreme merged commit caf5f2b into valkey-io:unstable Nov 9, 2026
65 checks passed
@JimB123 JimB123 moved this from Todo to To be backported in Valkey 9.2 Nov 9, 2026
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 9, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
Backport-Source-PR: 4785
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 10, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
(cherry picked from commit caf5f2b)
JimB123 pushed a commit that referenced this pull request Nov 10, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
Backport-Source-PR: 4785
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 9.2 Nov 10, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 9.1 Nov 11, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 9.0 Nov 11, 2026
sarthakaggarwal97 pushed a commit that referenced this pull request Nov 18, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
(cherry picked from commit caf5f2b)
sarthakaggarwal97 pushed a commit that referenced this pull request Nov 18, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
(cherry picked from commit caf5f2b)
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 9.0 Nov 18, 2026
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 20, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
Backport-Source-PR: 4785
valkeyrie-ops Bot pushed a commit that referenced this pull request Dec 2, 2026
The test asserted exact MEMORY USAGE equality between a hash and its COPY. With libc malloc (used by the sanitizer builds), the copy's fresh allocations and the source's realloc'd ones can report usable sizes 16 bytes apart. The CI failure was 288 vs 304.

The test now asserts that the encoding is preserved and that memory is within +/-16 bytes, matching the RESTORE variant of the neighbouring test. Test-only change, no behavior impact.

Reproduced on a MALLOC=libc build: about 0.2% of 4000 iterations differed by +/-16 bytes, across both encodings.

This PR is co-authored with Claude Opus 5.5.

Fixes #4149.

---------

Signed-off-by: Roy Chen <[email protected]>
Backport-Source-PR: 4785
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: To be backported
Status: Done

Development

Successfully merging this pull request may close these issues.

[TEST-FAILURE] COPY Preserves TTLs in tests/unit/hashexpire.tcl

2 participants