@@ -112,9 +112,15 @@ def securefs_mount(
112112 )
113113 try :
114114 for _ in range (600 ):
115- time .sleep (0.1 )
115+ try :
116+ p .wait (timeout = 0.1 )
117+ except subprocess .TimeoutExpired :
118+ pass
119+ if p .returncode :
120+ raise subprocess .CalledProcessError (p .returncode , p .args )
116121 if is_mount_then_statvfs (mount_point ):
117122 return p
123+
118124 raise TimeoutError (f"Failed to mount { repr (mount_point )} after many attempts" )
119125 except :
120126 securefs_unmount (p = p , mount_point = mount_point )
@@ -882,6 +888,30 @@ def test_regression(self):
882888 securefs_unmount (p , mount_point )
883889
884890
891+ class RepoLockerTestCase (unittest .TestCase ):
892+ def test_locked (self ):
893+ data_dir = get_data_dir (fmt = RepoFormat .FULL )
894+ securefs_create (data_dir = data_dir , fmt = RepoFormat .FULL , password = "123" )
895+ mount_point = get_mount_point ()
896+ with open (os .path .join (data_dir , ".securefs.lock" ), "w" ) as f :
897+ f .write (str (os .getpid ()))
898+ with self .assertRaises (subprocess .CalledProcessError ):
899+ p = securefs_mount (
900+ data_dir = data_dir , mount_point = mount_point , password = "123"
901+ )
902+
903+ def test_locker_died (self ):
904+ data_dir : str = get_data_dir (fmt = RepoFormat .FULL )
905+ securefs_create (data_dir = data_dir , fmt = RepoFormat .FULL , password = "123" )
906+ mount_point = get_mount_point ()
907+ with open (os .path .join (data_dir , ".securefs.lock" ), "w" ) as f :
908+ # Usually a recently finished process won't have its pid recycled so quickly.
909+ # However, in extreme circumstances this test may fail due to the assumption no longer true.
910+ f .write (str (2 ** 31 - 1 ))
911+ p = securefs_mount (data_dir = data_dir , mount_point = mount_point , password = "123" )
912+ securefs_unmount (p , mount_point )
913+
914+
885915def list_dir_recursive (dirname : str , relpath = False ) -> Set [str ]:
886916 # Note: os.walk does not work on Windows when crossing filesystem boundary.
887917 # So we use this crude version instead.
0 commit comments