Skip to content

gh-84649: Fix unstable test_rollover_at_midnight#154463

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:fix-test-rollover-tunneling
Jul 22, 2026
Merged

gh-84649: Fix unstable test_rollover_at_midnight#154463
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:fix-test-rollover-tunneling

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 22, 2026

Copy link
Copy Markdown
Member

The test was still unstable on Windows after GH-151813.

TimedRotatingFileHandler bases the rollover time on int(min(creation_time, modification_time)). The test unlinked the file created in setUp() and recreated it under the same name, and on Windows NTFS file tunneling restores the original creation time in that case. The rollover time was therefore earlier than the current time, and the first records were unexpectedly rolled over. This pre-created the rotated file, so the real rollover hit the if os.path.exists(dfn): return check in doRollover() and the following records were not rolled over.

Creating the log file in a fresh directory under a name which has never been used avoids tunneling.

On a Windows 11 VM the current test fails 6 times out of 40 runs, the fixed test 0 out of 120.

The test now also checks that the rollover does not happen before the specified time.

🤖 Generated with Claude Code

Create the log file in a fresh directory under a name which has never
been used.  On Windows, NTFS file tunneling restored the original
creation time of a file recreated with the same name, which made the
rollover time earlier than the current time and caused an unwanted
rollover.

Also check that the rollover does not happen before the specified time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka
serhiy-storchaka requested a review from vsajip as a code owner July 22, 2026 10:04
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 22, 2026
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) July 22, 2026 10:09
@serhiy-storchaka
serhiy-storchaka merged commit 7dc920a into python:main Jul 22, 2026
53 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the fix-test-rollover-tunneling branch July 22, 2026 12:52
@vstinner

Copy link
Copy Markdown
Member

The test unlinked the file created in setUp() and recreated it under the same name, and on Windows NTFS file tunneling restores the original creation time in that case.

Oh wow, that's a surprising issue! Using a temporary directory sounds like a reasonable fix for this issue.

Thanks for fixing it, it was failing randomly on CIs for a few weeks.

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

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants