Skip to content

gh-157161: Fix test_rollover_based_on_st_birthtime_only on slow machines - #157162

Open
iamsharduld wants to merge 2 commits into
python:mainfrom
iamsharduld:fix-logging-birthtime-test
Open

gh-157161: Fix test_rollover_based_on_st_birthtime_only on slow machines#157162
iamsharduld wants to merge 2 commits into
python:mainfrom
iamsharduld:fix-logging-birthtime-test

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The test looks for the rotated file by trying the timestamps of the last 5 seconds. The rotated file is named after the creation time of the log file (rolloverAt - interval, where rolloverAt was computed from the file's creation time), so it can only be found if the whole test took less than 5 seconds. Its nominal duration is 4.2 seconds of sleeps plus three handler set-ups, and on the failing CI job (diagnostics quoted in the issue) it took 6.07 seconds, so the file named after second 45 was never checked from second 51.

This derives the search window from the time the test actually took, plus two seconds: one because the log file is created in setUp(), slightly before the test starts, and one for the one-second resolution of the names.

Verified:

  • With a 1.2 s slowdown injected into each add_record() (a 7.8 s test), the current test fails with exactly the CI message, No rotated files found, went back 5 seconds; with this change it passes.
  • Without the slowdown it passes repeatedly, and the whole test_logging module passes with -u walltime.

The June change in GH-150954 widened the window by one timestamp; this makes it follow the actual duration so that no fixed value needs to be tuned again.

… machines

The rotated file is named after the creation time of the log file, but
the test only looked for it within a fixed 5 seconds before the end of
the test. On a slow CI runner the test took 6 seconds, so the file was
found nowhere and the test failed although the rollover was correct.

Derive the search window from the time the test actually took.
Comment thread Lib/test/test_logging.py Outdated
now = datetime.datetime.now()
GO_BACK = 5 # seconds
for secs in range(GO_BACK + 1):
go_back = int((now - start).total_seconds()) + 2

@brittanyrey brittanyrey Sep 8, 2026

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.

Would it make sense to include an inline comment on how this number is derived?
edit: or maybe rename s/go_back/total_time_spent (total_test_time, test_duration)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done. The window is now built in two named steps: test_duration from the measured elapsed time, then oldest = test_duration + 2, with a comment saying where the two seconds come from (the log file is created in setUp(), a moment before the test starts, and the suffix has a one second resolution).

Comment thread Lib/test/test_logging.py Outdated
GO_BACK = 5 # seconds
for secs in range(GO_BACK + 1):
go_back = int((now - start).total_seconds()) + 2
for secs in range(go_back + 1):

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.

Why add 2 on the line above, just to add 1 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were doing two different jobs, which is exactly why it read badly. The + 2 is the margin described above; the + 1 only makes range() cover oldest itself, since it is exclusive. The margin now has its own named variable and the loop carries an # inclusive of oldest comment, so neither number is bare arithmetic any more.

Split the search window into the measured duration of the test and an
explicit two second margin, and note that the range covers the oldest
second as well.
@iamsharduld

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Sep 9, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

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

Labels

awaiting change review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants