From 9c65ac52feb60de67b2cac651d41b0b3ce4c4e44 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 1 Feb 2012 14:23:04 +0000 Subject: Fix mtime handling in tests for chunk and stratum creation and unpacking Two things: * GNU tar does not, on Debian squeeze, set the full nanosecond timestamp value correctly. * The temporary directory from which the binaries get created gets modified (so the included files can be removed). Together, these things conspired to make the tests usually pass, but occasionally not, depending on timing. If everything happened within a whole calendar second, they passed. When the machine that runs our CI system got a lot of load from other things, tests sometimes, but not always, started taking more time, triggering the problem. Fix makes all non-directories have a known timestamp without subsecond fraction. Directories get ignored, since it's too hard to arrange for them to retain the timestamps when things get removed, and it doesn't really affect the usefulness of the test. --- morphlib/bins_tests.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'morphlib/bins_tests.py') diff --git a/morphlib/bins_tests.py b/morphlib/bins_tests.py index c23a22ad..86b55746 100644 --- a/morphlib/bins_tests.py +++ b/morphlib/bins_tests.py @@ -16,6 +16,7 @@ import os import shutil +import stat import tempfile import unittest @@ -41,7 +42,10 @@ class BinsTest(unittest.TestCase): def lstat(filename): st = os.lstat(filename) - return (st.st_mode, st.st_size, int(st.st_mtime)) + if stat.S_ISDIR(st.st_mode): + return (st.st_mode, 0, 0) + else: + return (st.st_mode, st.st_size, st.st_mtime) result = [] @@ -68,18 +72,24 @@ class ChunkTests(BinsTest): shutil.rmtree(self.tempdir) def populate_instdir(self): + timestamp = 12765 + os.mkdir(self.instdir) bindir = os.path.join(self.instdir, 'bin') os.mkdir(bindir) - with open(os.path.join(bindir, 'foo'), 'w'): + filename = os.path.join(bindir, 'foo') + with open(filename, 'w'): pass + os.utime(filename, (timestamp, timestamp)) libdir = os.path.join(self.instdir, 'lib') os.mkdir(libdir) - with open(os.path.join(libdir, 'libfoo.so'), 'w'): + filename = os.path.join(libdir, 'libfoo.so') + with open(filename, 'w'): pass - + os.utime(filename, (timestamp, timestamp)) + def test_empties_everything(self): self.populate_instdir() morphlib.bins.create_chunk(self.instdir, self.chunk_file, ['.'], -- cgit v1.2.1