@@ -801,6 +801,25 @@ def test_refresh(self):
801801 key1 : os .path .join ('new' , key1 ),
802802 key2 : os .path .join ('new' , key2 )})
803803
804+ def test_refresh_after_safety_period (self ):
805+ # Issue #13254: Call _refresh after the "file system safety
806+ # period" of 2 seconds has passed; _toc should still be
807+ # updated because this is the first call to _refresh.
808+ key0 = self ._box .add (self ._template % 0 )
809+ key1 = self ._box .add (self ._template % 1 )
810+
811+ self ._box = self ._factory (self ._path )
812+ self .assertEqual (self ._box ._toc , {})
813+
814+ # Emulate sleeping. Instead of sleeping for 2 seconds, use the
815+ # skew factor to make _refresh think that the filesystem
816+ # safety period has passed and re-reading the _toc is only
817+ # required if mtimes differ.
818+ self ._box ._skewfactor = - 2
819+
820+ self ._box ._refresh ()
821+ self .assertEqual (sorted (self ._box ._toc .keys ()), sorted ([key0 , key1 ]))
822+
804823 def test_lookup (self ):
805824 # Look up message subpaths in the TOC
806825 self .assertRaises (KeyError , lambda : self ._box ._lookup ('foo' ))
@@ -876,6 +895,8 @@ def test_folder_file_perms(self):
876895 self .assertFalse ((perms & 0o111 )) # Execute bits should all be off.
877896
878897 def test_reread (self ):
898+ # Do an initial unconditional refresh
899+ self ._box ._refresh ()
879900
880901 # Put the last modified times more than two seconds into the past
881902 # (because mtime may have a two second granularity)
0 commit comments