summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2011-05-06 18:06:00 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2011-05-06 18:06:00 (GMT)
commita6bbbe43efa9b4e71cd793c9a13b7158846a9590 (patch)
tree6d1f47b4265bd0a62b749a967401b84dd5b80b46 /Lib
parentd78def9474ceac79576e0b6382b15c90cc54aff8 (diff)
downloadcpython-a6bbbe43efa9b4e71cd793c9a13b7158846a9590.zip
cpython-a6bbbe43efa9b4e71cd793c9a13b7158846a9590.tar.gz
cpython-a6bbbe43efa9b4e71cd793c9a13b7158846a9590.tar.bz2
Refined rollover test for slow test machines.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_logging.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 919f0b2..aa70295 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3490,23 +3490,24 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
self.assertLogFile(self.fn)
time.sleep(1.0)
fh.emit(r)
+ # 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.
+ found = False
now = datetime.datetime.now()
- prevsec = now - datetime.timedelta(seconds=1)
- earlier = now - datetime.timedelta(seconds=2)
- fn1 = self.fn + prevsec.strftime(".%Y-%m-%d_%H-%M-%S")
- fn2 = self.fn + earlier.strftime(".%Y-%m-%d_%H-%M-%S")
- success = os.path.exists(fn1) or os.path.exists(fn2)
- if not success:
- # print additional diagnostic information
- print('Neither %s nor %s exists' % (fn1, fn2), file=sys.stderr)
- dirname = os.path.dirname(fn1)
- files = os.listdir(dirname)
- files = [f for f in files if f.startswith('test_logging-2-')]
- print('matching files: %s' % files, file=sys.stderr)
- self.assertTrue(success)
- for fn in (fn1, fn2):
- if os.path.exists(fn):
+ GO_BACK = 2 * 60 # seconds
+ for secs in range(1, GO_BACK):
+ 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
+ self.assertTrue(found, msg=msg)
finally:
fh.close()