Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9a428d

Browse files
committed
#9557: eliminate 3 seconds of static overhead from test_mailbox.
This patch doesn't quite fix the 'run in a VM with Samba share' timing problem, but it should at least make it better.
1 parent ebbf1e6 commit b9a428d

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/test/test_mailbox.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,6 @@ def test_folder_file_perms(self):
741741
self.assertFalse((perms & 0o111)) # Execute bits should all be off.
742742

743743
def test_reread(self):
744-
# Wait for 2 seconds
745-
time.sleep(2)
746744

747745
# Initially, the mailbox has not been read and the time is null.
748746
assert getattr(self._box, '_last_read', None) is None
@@ -751,15 +749,21 @@ def test_reread(self):
751749
self._box._refresh()
752750
assert getattr(self._box, '_last_read', None) is not None
753751

754-
# Try calling _refresh() again; the modification times shouldn't have
755-
# changed, so the mailbox should not be re-reading. Re-reading causes
756-
# the ._toc attribute to be assigned a new dictionary object, so
757-
# we'll check that the ._toc attribute isn't a different object.
752+
# Put the last modified times more than one second into the past
753+
# (because mtime has a one second granularity, a refresh is done
754+
# unconditionally if called for within the same second, just in case
755+
# the mbox has changed).
756+
for subdir in ('cur', 'new'):
757+
os.utime(os.path.join(self._box._path, subdir),
758+
(time.time()-5,)*2)
759+
760+
# Re-reading causes the ._toc attribute to be assigned a new dictionary
761+
# object, so we'll check that the ._toc attribute isn't a different
762+
# object.
758763
orig_toc = self._box._toc
759764
def refreshed():
760765
return self._box._toc is not orig_toc
761766

762-
time.sleep(1) # Wait 1sec to ensure time.time()'s value changes
763767
self._box._refresh()
764768
assert not refreshed()
765769

0 commit comments

Comments
 (0)