Skip to content

test_logging: rotation tests fails on Windows, macOS and FreeBSD #150960

Closed

Description

@vstinner

Bug report

Example on macOS:

FAIL: test_rollover_based_on_st_birthtime_only (test.test_logging.TimedRotatingFileHandlerTest.test_rollover_based_on_st_birthtime_only)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/pull_request.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_logging.py", line 6666, in test_rollover_based_on_st_birthtime_only
    self.assertTrue(found, msg=msg)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
AssertionError: False is not true : No rotated files found, went back 5 seconds

Example on Windows:

FAIL: test_rollover_based_on_st_birthtime_only (test.test_logging.TimedRotatingFileHandlerTest.test_rollover_based_on_st_birthtime_only)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\bbarea\pull_request.itamaro-win64-srv-22-aws.tailcall.pgo\build\Lib\test\test_logging.py", line 6666, in test_rollover_based_on_st_birthtime_only
    self.assertTrue(found, msg=msg)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
AssertionError: False is not true : No rotated files found, went back 5 seconds

Stdout:
Contents of test_logging-2-njcaf5hh.log:
os.stat_result(st_mode=33206, st_ino=116249165381905831, st_dev=5772745545947373322, st_nlink=1, st_uid=0, st_gid=0, st_size=88, st_atime=1780658874, st_mtime=1780658874, st_ctime=1780658869)
2026-06-05 11:27:54,029 testing - new record supposedly in the new file after rollover

Contents of test_logging-2-njcaf5hh.log.2026-06-05_11-27-49:
os.stat_result(st_mode=33206, st_ino=167477611143228771, st_dev=5772745545947373322, st_nlink=1, st_uid=0, st_gid=0, st_size=123, st_atime=1780658871, st_mtime=1780658871, st_ctime=1780658869)
2026-06-05 11:27:49,817 testing - initial
2026-06-05 11:27:51,921 testing - update before rollover to renew the st_mtime


Stderr:
Test time: 2026-06-05 11-27-54
The only matching files are: ['test_logging-2-njcaf5hh.log', 'test_logging-2-njcaf5hh.log.2026-06-05_11-27-49']

Activity

  1. added
    type-bug
    tests
    on Jun 5, 2026
  2. sergey-miryanov commented on Jun 5, 2026

    @sergey-miryanov
    Contributor
  3. vstinner commented on Jun 5, 2026

    @vstinner
    MemberAuthor

    It seems like the test_logging regression was introduced by the change commit ac3694b:

    commit ac3694b008e4f9d5d5ea6ff8584078f92f6906ab
    Author: Ivan Marton <github@martonivan.hu>
    Date:   Thu Jun 4 15:50:33 2026 +0200
    
        gh-84649: Make TimedRotatingFileHandler use CTIME instead of MTIME (GH-24660)
        
        The TimedRotatingFileHandler previously only used st_mtime attribute of the
        log file to detect whether it has to be rotate yet or not. In cases when the
        file is changed within the rotatation period the st_mtime is also updated
        to the current time and the rotation never happens.
        
        It's more appropriate to check the file creation time (st_ctime) instead.
        Whenever available, the more appropriate st_birthtime will be in use. (This
        feature is available on FreeBSD, MacOS and Windows at the moment.) If
        the st_mtime would be newer than st_ctime (e.g.: because the inode
        related to the file has been changed without any file content
        modification), then the earliest attribute will be used.
    
  4. vstinner commented on Jun 5, 2026

    @vstinner
    MemberAuthor

    The test fails randomly. python -m test -v test_logging -m test_rollover_based_on_st_birthtime_only -F can be used to reproduce the bug (it may take a few iterations before hitting the bug).

  5. serhiy-storchaka commented on Jun 5, 2026

    @serhiy-storchaka
    Member

    #150954 fixes it. Before it, the test failed after 5-10 iterations, with it, it did not fail after more than a hundred.

  6. vstinner commented on Jun 5, 2026

    @vstinner
    MemberAuthor

    #150954 fixes it. Before it, the test failed after 5-10 iterations, with it, it did not fail after more than a hundred.

    I confirm that I fail to reproduce the issue after 1000 iterations of python -m test -v test_logging -m test_rollover_based_on_st_birthtime_only -F on Windows and FreeBSD.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    teststype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions