diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-05-12 16:18:29 +0100 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-05-12 16:18:29 +0100 |
commit | 06c768a35abc2bf17d987830d58acb11e6e58992 (patch) | |
tree | e91417ad9e488b9bc9300c3f122a839acd0ad219 /Lib/test/test_logging.py | |
parent | 3dba024d20bf373615f09e30ddcc5b1b3ff7c505 (diff) | |
download | cpython-git-06c768a35abc2bf17d987830d58acb11e6e58992.tar.gz |
TimedTRotatingFileHandler test now improved to minimise chances of failure on very slow machines.
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index c68de1045f..93cf669ef0 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3502,6 +3502,7 @@ class TimedRotatingFileHandlerTest(BaseFileTest): fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S', backupCount=1) r = logging.makeLogRecord({'msg': 'testing'}) + start = datetime.datetime.now() fh.emit(r) self.assertLogFile(self.fn) time.sleep(1.0) @@ -3510,20 +3511,21 @@ class TimedRotatingFileHandlerTest(BaseFileTest): # At this point, we should have a recent rotated file which we # can test for the existence of. However, in practice, on some # 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 a fair - # bit, and stop as soon as we see a rotated file. In theory this - # could of course still fail, but the chances are lower. + # in time to go to look for the log file. So, we go back as far as + # when the test started, and stop as soon as we see a rotated file. found = False now = datetime.datetime.now() - GO_BACK = 2 * 60 # seconds - for secs in range(1, GO_BACK): - prev = now - datetime.timedelta(seconds=secs) + secs = 1 + prev = now - datetime.timedelta(seconds=secs) + while prev > start: 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 + secs += 1 + prev -= datetime.timedelta(seconds=1) + msg = 'No rotated files found, went back %d seconds' % secs self.assertTrue(found, msg=msg) def test_invalid(self): |