tests: use same_ts_ns for all timestamp comparisons

This commit is contained in:
Thomas Waldmann 2023-02-11 17:08:56 +01:00
parent 2ef09eaa77
commit aee17a87e2
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
3 changed files with 22 additions and 16 deletions

View file

@ -23,6 +23,7 @@ from .. import (
are_fifos_supported,
is_utime_fully_supported,
is_birthtime_fully_supported,
same_ts_ns,
)
from . import (
ArchiverTestCaseBase,
@ -151,9 +152,10 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd(f"--repo={self.repository_location}", "extract", "test")
sti = os.stat("input/file1")
sto = os.stat("output/input/file1")
assert int(sti.st_birthtime * 1e9) == birthtime * 1e9
assert int(sto.st_birthtime * 1e9) == mtime * 1e9
assert sti.st_mtime_ns == sto.st_mtime_ns == mtime * 1e9
assert same_ts_ns(sti.st_birthtime * 1e9, birthtime * 1e9)
assert same_ts_ns(sto.st_birthtime * 1e9, mtime * 1e9)
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
assert same_ts_ns(sto.st_mtime_ns, mtime * 1e9)
def test_create_stdin(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)

View file

@ -11,7 +11,7 @@ from ...chunker import has_seek_hole
from ...constants import * # NOQA
from ...helpers import EXIT_WARNING
from ...helpers import flags_noatime, flags_normal
from .. import changedir
from .. import changedir, same_ts_ns
from .. import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported, is_birthtime_fully_supported
from ..platform import is_darwin
from . import (
@ -73,7 +73,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
# make sure borg fixes the directory mtime after touching it
sti = os.stat("input/dir2")
sto = os.stat("output/input/dir2")
assert sti.st_mtime_ns == sto.st_mtime_ns
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")
def test_directory_timestamps2(self):
@ -90,7 +90,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
# make sure borg fixes the directory mtime after touching it
sti = os.stat("input/dir2")
sto = os.stat("output/input/dir2")
assert sti.st_mtime_ns == sto.st_mtime_ns
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")
def test_directory_timestamps3(self):
@ -107,7 +107,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
# make sure borg fixes the directory mtime after touching it
sti = os.stat("input/dir2")
sto = os.stat("output/input/dir2")
assert sti.st_mtime_ns == sto.st_mtime_ns
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")
def test_atime(self):
@ -133,12 +133,14 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd(f"--repo={self.repository_location}", "extract", "test")
sti = os.stat("input/file1")
sto = os.stat("output/input/file1")
assert sti.st_mtime_ns == sto.st_mtime_ns == mtime * 1e9
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
assert same_ts_ns(sto.st_mtime_ns, mtime * 1e9)
if have_noatime:
assert sti.st_atime_ns == sto.st_atime_ns == atime * 1e9
assert same_ts_ns(sti.st_atime_ns, sto.st_atime_ns)
assert same_ts_ns(sto.st_atime_ns, atime * 1e9)
else:
# it touched the input file's atime while backing it up
assert sto.st_atime_ns == atime * 1e9
assert same_ts_ns(sto.st_atime_ns, atime * 1e9)
@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")
@pytest.mark.skipif(
@ -155,8 +157,10 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd(f"--repo={self.repository_location}", "extract", "test")
sti = os.stat("input/file1")
sto = os.stat("output/input/file1")
assert int(sti.st_birthtime * 1e9) == int(sto.st_birthtime * 1e9) == birthtime * 1e9
assert sti.st_mtime_ns == sto.st_mtime_ns == mtime * 1e9
assert same_ts_ns(sti.st_birthtime * 1e9, sto.st_birthtime * 1e9)
assert same_ts_ns(sto.st_birthtime * 1e9, birthtime * 1e9)
assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
assert same_ts_ns(sto.st_mtime_ns, mtime * 1e9)
def test_sparse_file(self):
def is_sparse(fn, total_size, hole_size):

View file

@ -11,7 +11,7 @@ from ...constants import * # NOQA
from ...locking import Lock
from ...helpers import flags_noatime, flags_normal
from .. import has_lchflags, llfuse
from .. import changedir, no_selinux
from .. import changedir, no_selinux, same_ts_ns
from .. import are_symlinks_supported, are_hardlinks_supported, are_fifos_supported
from ..platform import fakeroot_detected
from . import (
@ -109,9 +109,9 @@ class ArchiverTestCase(ArchiverTestCaseBase):
assert sti1.st_gid == sto1.st_gid
assert sti1.st_size == sto1.st_size
if have_noatime:
assert sti1.st_atime == sto1.st_atime
assert sti1.st_ctime == sto1.st_ctime
assert sti1.st_mtime == sto1.st_mtime
assert same_ts_ns(sti1.st_atime * 1e9, sto1.st_atime * 1e9)
assert same_ts_ns(sti1.st_ctime * 1e9, sto1.st_ctime * 1e9)
assert same_ts_ns(sti1.st_mtime * 1e9, sto1.st_mtime * 1e9)
if are_hardlinks_supported():
# note: there is another hardlink to this, see below
assert sti1.st_nlink == sto1.st_nlink == 2