# HG changeset patch # User Jun Wu # Date 1506710484 25200 # Node ID 12b355964de8db35ad0a7c28c86d71fd225a8b9b # Parent 98b35921691504a4eaad97c1efac75ad3493d9d2 test-patchbomb: use mocktime The test was using system time for displaying ETAs, which could be flaky if the sysload is high. This patch extracts mocktime.py from test-progress.t to make sure test-patchbomb.t is unaffected by system time. Differential Revision: https://phab.mercurial-scm.org/D844 diff -r 98b359216915 -r 12b355964de8 tests/mocktime.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mocktime.py Fri Sep 29 11:41:24 2017 -0700 @@ -0,0 +1,18 @@ +from __future__ import absolute_import + +import os +import time + +class mocktime(object): + def __init__(self, increment): + self.time = 0 + self.increment = [float(s) for s in increment.split()] + self.pos = 0 + + def __call__(self): + self.time += self.increment[self.pos % len(self.increment)] + self.pos += 1 + return self.time + +def uisetup(ui): + time.time = mocktime(os.environ.get('MOCKTIME', '0.1')) diff -r 98b359216915 -r 12b355964de8 tests/test-patchbomb.t --- a/tests/test-patchbomb.t Thu Sep 28 10:37:53 2017 -0700 +++ b/tests/test-patchbomb.t Fri Sep 29 11:41:24 2017 -0700 @@ -323,7 +323,8 @@ $ hg email -m test.mbox -f quux -t foo -c bar -s test 0:tip \ > --config extensions.progress= --config progress.assume-tty=1 \ > --config progress.delay=0 --config progress.refresh=0 \ - > --config progress.width=60 + > --config progress.width=60 \ + > --config extensions.mocktime=$TESTDIR/mocktime.py this patch series consists of 2 patches. diff -r 98b359216915 -r 12b355964de8 tests/test-progress.t --- a/tests/test-progress.t Thu Sep 28 10:37:53 2017 -0700 +++ b/tests/test-progress.t Fri Sep 29 11:41:24 2017 -0700 @@ -185,27 +185,9 @@ #if no-chg - $ cat > mocktime.py < import os - > import time - > - > class mocktime(object): - > def __init__(self, increment): - > self.time = 0 - > self.increment = [int(s) for s in increment.split()] - > self.pos = 0 - > def __call__(self): - > self.time += self.increment[self.pos % len(self.increment)] - > self.pos += 1 - > return self.time - > - > def uisetup(ui): - > time.time = mocktime(os.environ.get('MOCKTIME', '11')) - > EOF - $ cp $HGRCPATH.orig $HGRCPATH $ echo "[extensions]" >> $HGRCPATH - $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH + $ echo "mocktime=$TESTDIR/mocktime.py" >> $HGRCPATH $ echo "progress=" >> $HGRCPATH $ echo "loop=`pwd`/loop.py" >> $HGRCPATH $ echo "[progress]" >> $HGRCPATH @@ -213,7 +195,7 @@ $ echo "delay=25" >> $HGRCPATH $ echo "width=60" >> $HGRCPATH - $ hg -y loop 8 + $ MOCKTIME=11 hg -y loop 8 \r (no-eol) (esc) loop [=========> ] 2/8 1m07s\r (no-eol) (esc) loop [===============> ] 3/8 56s\r (no-eol) (esc) @@ -274,7 +256,7 @@ \r (no-eol) (esc) Time estimates should not fail when there's no end point: - $ hg -y loop -- -4 + $ MOCKTIME=11 hg -y loop -- -4 \r (no-eol) (esc) loop [ <=> ] 2\r (no-eol) (esc) loop [ <=> ] 3\r (no-eol) (esc)