FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157161: Fix test_rollover_based_on_st_birthtime_only on slow machines by iamsharduld · Pull Request #157162 · python/cpython · GitHub

Repository navigation

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 12 additions & 5 deletions Lib/test/test_logging.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6752,6 +6752,7 @@ def add_record(message: str) -> None:
fh.emit(record)
fh.close()

start = datetime.datetime.now()
add_record('testing - initial')
self.assertLogFile(self.fn)
# Sleep a little over the half of rollover time - and this value
Expand All @@ -6764,18 +6765,24 @@ def add_record(message: str) -> None:

# At this point, the log file should be rotated if the rotation
# is based on creation time but should be not if it's based on
# modification time.
found = False
# modification time. The rotated file is named after the creation
# time of the log file, so search back over the whole time the test
# took rather than over a fixed number of seconds.
now = datetime.datetime.now()
GO_BACK = 5 # seconds
for secs in range(GO_BACK + 1):
test_duration = int((now - start).total_seconds())
# Two seconds of margin on top of that: the log file is created in
# setUp(), a moment before the test starts, and the name has a
# resolution of one second.
oldest = test_duration + 2
found = False
for secs in range(oldest + 1): # inclusive of oldest
prev = now - datetime.timedelta(seconds=secs)
fn = self.fn + prev.strftime(".%Y-%m-%d_%H-%M-%S")
found = os.path.exists(fn)
if found:
self.rmfiles.append(fn)
break
msg = 'No rotated files found, went back %d seconds' % GO_BACK
msg = 'No rotated files found, went back %d seconds' % oldest
if not found:
# print additional diagnostics
dn, fn = os.path.split(self.fn)
Expand Down
Loading

Back | FazBrowse Home | New Git URL