mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Added diagnostics to test_logging, after reverting last change.
This commit is contained in:
parent
93ea851e83
commit
672c581633
1 changed files with 12 additions and 9 deletions
|
@ -3502,7 +3502,6 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
|
||||||
fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S',
|
fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S',
|
||||||
backupCount=1)
|
backupCount=1)
|
||||||
r = logging.makeLogRecord({'msg': 'testing'})
|
r = logging.makeLogRecord({'msg': 'testing'})
|
||||||
start = datetime.datetime.now()
|
|
||||||
fh.emit(r)
|
fh.emit(r)
|
||||||
self.assertLogFile(self.fn)
|
self.assertLogFile(self.fn)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
|
@ -3511,21 +3510,25 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
|
||||||
# At this point, we should have a recent rotated file which we
|
# At this point, we should have a recent rotated file which we
|
||||||
# can test for the existence of. However, in practice, on some
|
# can test for the existence of. However, in practice, on some
|
||||||
# machines which run really slowly, we don't know how far back
|
# machines which run really slowly, we don't know how far back
|
||||||
# in time to go to look for the log file. So, we go back as far as
|
# in time to go to look for the log file. So, we go back a fair
|
||||||
# when the test started, and stop as soon as we see a rotated file.
|
# bit, and stop as soon as we see a rotated file. In theory this
|
||||||
|
# could of course still fail, but the chances are lower.
|
||||||
found = False
|
found = False
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
secs = 1
|
GO_BACK = 2 * 60 # seconds
|
||||||
|
for secs in range(GO_BACK):
|
||||||
prev = now - datetime.timedelta(seconds=secs)
|
prev = now - datetime.timedelta(seconds=secs)
|
||||||
while prev > start:
|
|
||||||
fn = self.fn + prev.strftime(".%Y-%m-%d_%H-%M-%S")
|
fn = self.fn + prev.strftime(".%Y-%m-%d_%H-%M-%S")
|
||||||
found = os.path.exists(fn)
|
found = os.path.exists(fn)
|
||||||
if found:
|
if found:
|
||||||
self.rmfiles.append(fn)
|
self.rmfiles.append(fn)
|
||||||
break
|
break
|
||||||
secs += 1
|
msg = 'No rotated files found, went back %d seconds' % GO_BACK
|
||||||
prev -= datetime.timedelta(seconds=1)
|
if not found:
|
||||||
msg = 'No rotated files found, went back %d seconds' % secs
|
#print additional diagnostics
|
||||||
|
dn = os.path.dirname(self.fn)
|
||||||
|
files = [f for f in os.listdir(dn) if f.startswith(self.fn)]
|
||||||
|
print('The only matching files are: %s' % files)
|
||||||
self.assertTrue(found, msg=msg)
|
self.assertTrue(found, msg=msg)
|
||||||
|
|
||||||
def test_invalid(self):
|
def test_invalid(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue