Skip to content

Commit dffb770

Browse files
committed
Address review: name the margin and explain the two additions
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.
1 parent 34d838a commit dffb770

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Lib/test/test_logging.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6766,20 +6766,23 @@ def add_record(message: str) -> None:
67666766
# At this point, the log file should be rotated if the rotation
67676767
# is based on creation time but should be not if it's based on
67686768
# modification time. The rotated file is named after the creation
6769-
# time of the log file, so look back over the whole duration of the
6770-
# test, plus a margin: the file was created in setUp(), and the
6771-
# names have a resolution of one second.
6772-
found = False
6769+
# time of the log file, so search back over the whole time the test
6770+
# took rather than over a fixed number of seconds.
67736771
now = datetime.datetime.now()
6774-
go_back = int((now - start).total_seconds()) + 2
6775-
for secs in range(go_back + 1):
6772+
test_duration = int((now - start).total_seconds())
6773+
# Two seconds of margin on top of that: the log file is created in
6774+
# setUp(), a moment before the test starts, and the name has a
6775+
# resolution of one second.
6776+
oldest = test_duration + 2
6777+
found = False
6778+
for secs in range(oldest + 1): # inclusive of oldest
67766779
prev = now - datetime.timedelta(seconds=secs)
67776780
fn = self.fn + prev.strftime(".%Y-%m-%d_%H-%M-%S")
67786781
found = os.path.exists(fn)
67796782
if found:
67806783
self.rmfiles.append(fn)
67816784
break
6782-
msg = 'No rotated files found, went back %d seconds' % go_back
6785+
msg = 'No rotated files found, went back %d seconds' % oldest
67836786
if not found:
67846787
# print additional diagnostics
67856788
dn, fn = os.path.split(self.fn)

0 commit comments

Comments
 (0)