Skip to content

Fixed: The disk's cap test no longer depends on the clock moving to the next second - #7

Open
se7enxweb wants to merge 1 commit into
cjw-network:mainfrom
se7enxweb:rs-pr-disk-cap-test-mtimes
Open

se7enxweb wants to merge 1 commit into
cjw-network:mainfrom
se7enxweb:rs-pr-disk-cap-test-mtimes

Conversation

@se7enxweb

@se7enxweb se7enxweb commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What fails

CacheTest > RSF04-03 the disk's cap (http-cache-disk) fails now and then on
a slow leg. It was seen on PHP 8.0 + APCu, in a run of a92a37b plus the role
test fix:

https://github.com/se7enxweb/request-shield/actions/runs/38120981093/job/114415779306

FAIL  CacheTest > RSF04-03 the disk's cap (http-cache-disk): each folder holds ...
      the newest kept, the oldest gone

The same commit passed on that leg in the next run, so the failure depends on timing.

Why

The test writes answers in a loop, one after another, and after each write
sets the mtimes by hand, touch($file, time() + $n), so the older answers
stay older. Those mtimes lie in the future.

With APCu, FileCache::put() trims the folder inside put(), while it
writes the new answer, whose mtime is the real "now". Next to answers dated
time() + 1, time() + 2 …, the answer being written is the oldest one in
the folder, or as old as the first one when the clock moves to the next second
during the loop. Which answer is taken out then depends on whether a second
passed, not on the order of writing. A fast machine finishes within one
second and passes. A slow 8.0 leg sometimes does not.

The fix

Test only, in tests/CacheTest.php: the mtimes are set one second apart in
the past, touch($file, $base + $n) with $base = time() - 100. The
answer put() is writing is then always the newest, as on a real site. The
test still checks the same thing, with and without APCu: past the folder's
share, the oldest answers go and the newest stays.

Tested

…nd apart in the past, so the answer put() is writing is always the newest -- with APCu the folder is trimmed inside put(), and the mtimes in the future made the new answer the oldest or as old as the first when a second passed

It failed now and then on a slow leg (PHP 8.0 with APCu: "the newest kept,
the oldest gone"): which answer was taken out depended on whether the clock
moved to the next second during the loop. It still holds the same: past the
folder's share the oldest go, the newest stays, with and without APCu.

This branch has not been deployed

No deployments
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.

1 participant