5757from ..remote import RemoteRepository , PathNotAllowed
5858from ..repository import Repository
5959from . import has_lchflags , llfuse
60- from . import BaseTestCase , changedir , environment_variable , no_selinux , same_ts_ns
60+ from . import BaseTestCase , changedir , environment_variable , no_selinux , same_ts_ns , granularity_sleep
6161from . import are_symlinks_supported , are_hardlinks_supported , are_fifos_supported , is_utime_fully_supported , is_birthtime_fully_supported
6262from .platform import fakeroot_detected , is_darwin , is_freebsd , is_win32
6363from .upgrader import make_attic_repo
@@ -383,7 +383,7 @@ def create_test_files(self, create_hardlinks=True):
383383 if e .errno not in (errno .EINVAL , errno .ENOSYS ):
384384 raise
385385 have_root = False
386- time . sleep ( 1 ) # "empty" must have newer timestamp than other files
386+ granularity_sleep ( ) # ensure "empty" has a newer timestamp than other files across filesystems
387387 self .create_regular_file ('empty' , size = 0 )
388388 return have_root
389389
@@ -2074,7 +2074,7 @@ def test_file_status(self):
20742074
20752075 clearly incomplete: only tests for the weird "unchanged" status for now"""
20762076 self .create_regular_file ('file1' , size = 1024 * 80 )
2077- time . sleep ( 1 ) # file2 must have newer timestamps than file1
2077+ granularity_sleep ( ) # file2 must have newer timestamps than file1
20782078 self .create_regular_file ('file2' , size = 1024 * 80 )
20792079 self .cmd ('init' , '--encryption=repokey' , self .repository_location )
20802080 output = self .cmd ('create' , '--list' , self .repository_location + '::test' , 'input' )
@@ -2090,7 +2090,7 @@ def test_file_status(self):
20902090 def test_file_status_cs_cache_mode (self ):
20912091 """test that a changed file with faked "previous" mtime still gets backed up in ctime,size cache_mode"""
20922092 self .create_regular_file ('file1' , contents = b'123' )
2093- time . sleep ( 1 ) # file2 must have newer timestamps than file1
2093+ granularity_sleep ( ) # file2 must have newer timestamps than file1
20942094 self .create_regular_file ('file2' , size = 10 )
20952095 self .cmd ('init' , '--encryption=repokey' , self .repository_location )
20962096 output = self .cmd ('create' , '--list' , '--files-cache=ctime,size' , self .repository_location + '::test1' , 'input' )
@@ -2105,7 +2105,7 @@ def test_file_status_cs_cache_mode(self):
21052105 def test_file_status_ms_cache_mode (self ):
21062106 """test that a chmod'ed file with no content changes does not get chunked again in mtime,size cache_mode"""
21072107 self .create_regular_file ('file1' , size = 10 )
2108- time . sleep ( 1 ) # file2 must have newer timestamps than file1
2108+ granularity_sleep ( ) # file2 must have newer timestamps than file1
21092109 self .create_regular_file ('file2' , size = 10 )
21102110 self .cmd ('init' , '--encryption=repokey' , self .repository_location )
21112111 output = self .cmd ('create' , '--list' , '--files-cache=mtime,size' , self .repository_location + '::test1' , 'input' )
@@ -2119,7 +2119,7 @@ def test_file_status_ms_cache_mode(self):
21192119 def test_file_status_rc_cache_mode (self ):
21202120 """test that files get rechunked unconditionally in rechunk,ctime cache mode"""
21212121 self .create_regular_file ('file1' , size = 10 )
2122- time . sleep ( 1 ) # file2 must have newer timestamps than file1
2122+ granularity_sleep ( ) # file2 must have newer timestamps than file1
21232123 self .create_regular_file ('file2' , size = 10 )
21242124 self .cmd ('init' , '--encryption=repokey' , self .repository_location )
21252125 output = self .cmd ('create' , '--list' , '--files-cache=rechunk,ctime' , self .repository_location + '::test1' , 'input' )
@@ -2131,7 +2131,7 @@ def test_file_status_excluded(self):
21312131 """test that excluded paths are listed"""
21322132
21332133 self .create_regular_file ('file1' , size = 1024 * 80 )
2134- time . sleep ( 1 ) # file2 must have newer timestamps than file1
2134+ granularity_sleep ( ) # file2 must have newer timestamps than file1
21352135 self .create_regular_file ('file2' , size = 1024 * 80 )
21362136 if has_lchflags :
21372137 self .create_regular_file ('file3' , size = 1024 * 80 )
@@ -4753,7 +4753,7 @@ def test_basic_functionality(self):
47534753 self .create_regular_file ('file_replaced' , contents = b'0' * 4096 )
47544754 os .unlink ('input/file_removed' )
47554755 os .unlink ('input/file_removed2' )
4756- time . sleep ( 1 ) # macOS HFS+ has a 1s timestamp granularity
4756+ granularity_sleep ( ) # cover FS timestamp granularity differences (e.g. HFS+ 1s)
47574757 Path ('input/file_touched' ).touch ()
47584758 os .rmdir ('input/dir_replaced_with_file' )
47594759 self .create_regular_file ('dir_replaced_with_file' , size = 8192 )
@@ -5053,20 +5053,15 @@ def test_time_diffs(self):
50535053 self .cmd ('init' , '--encryption=repokey' , self .repository_location )
50545054 self .create_regular_file ("test_file" , size = 10 )
50555055 self .cmd ('create' , self .repository_location + '::archive1' , 'input' )
5056- time . sleep ( 0.1 )
5056+ granularity_sleep ( )
50575057 os .unlink ("input/test_file" )
5058- if is_win32 :
5059- # Sleeping for 15s because Windows doesn't refresh ctime if file is deleted and recreated within 15 seconds.
5060- time .sleep (15 )
5061- elif is_darwin :
5062- time .sleep (1 ) # HFS has a 1s timestamp granularity
5058+ granularity_sleep (ctime_quirk = True )
50635059 self .create_regular_file ("test_file" , size = 15 )
50645060 self .cmd ('create' , self .repository_location + '::archive2' , 'input' )
50655061 output = self .cmd ("diff" , self .repository_location + "::archive1" , "archive2" )
50665062 self .assert_in ("mtime" , output )
50675063 self .assert_in ("ctime" , output ) # Should show up on windows as well since it is a new file.
5068- if is_darwin :
5069- time .sleep (1 ) # HFS has a 1s timestamp granularity
5064+ granularity_sleep ()
50705065 os .chmod ("input/test_file" , 0o777 )
50715066 self .cmd ('create' , self .repository_location + '::archive3' , 'input' )
50725067 output = self .cmd ("diff" , self .repository_location + "::archive2" , "archive3" )
0 commit comments