diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-02-01 14:23:04 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-02-01 14:23:04 +0000 |
commit | 9c65ac52feb60de67b2cac651d41b0b3ce4c4e44 (patch) | |
tree | 2c639fbe57dbdff8de50b9a70dc2637ff1be0af6 /morphlib/bins_tests.py | |
parent | 1a008aba3c5cc4510275e502df44bf8a37ee21f6 (diff) | |
download | morph-9c65ac52feb60de67b2cac651d41b0b3ce4c4e44.tar.gz |
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.
Diffstat (limited to 'morphlib/bins_tests.py')
-rw-r--r-- | morphlib/bins_tests.py | 18 |
1 files changed, 14 insertions, 4 deletions
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, ['.'], |