# HG changeset patch # User Boris Feld # Date 1567000876 -7200 # Node ID 2c74337e6483e59c1e66830eb90725cc350bda49 # Parent ce6797ef6eab33f0255b940ff6b628215762a84b remotefilelog: reduce probability of race-condition in remotefilelog tests ca1014ad3de4 introduced a new parameter `ensurestart` to speed up remotefilelog background processes start. Unfortunately it seems to have increased the possibility of race-conditions in remotefilelog tests testing those background processes. With `ensurestart=False`, it seems that it's more probable to enter in a race condition with `debugwaitonprefetch` and `debugwaitonrepack` in remotefilelog background tests. Our CI seems to have a high probability of triggering this race condition so make it configurable to ensure tests are stable. Differential Revision: https://phab.mercurial-scm.org/D6772 diff -r ce6797ef6eab -r 2c74337e6483 hgext/remotefilelog/__init__.py --- a/hgext/remotefilelog/__init__.py Sat Aug 31 14:12:38 2019 +0900 +++ b/hgext/remotefilelog/__init__.py Wed Aug 28 16:01:16 2019 +0200 @@ -224,6 +224,8 @@ configitem('packs', 'maxpacksize', default=0) configitem('packs', 'maxchainlen', default=1000) +configitem('devel', 'remotefilelog.ensurestart', default=False) + # default TTL limit is 30 days _defaultlimit = 60 * 60 * 24 * 30 configitem('remotefilelog', 'nodettl', default=_defaultlimit) @@ -949,19 +951,23 @@ prefetchrevset = ui.config('remotefilelog', 'pullprefetch') bgrepack = repo.ui.configbool('remotefilelog', 'backgroundrepack') bgprefetch = repo.ui.configbool('remotefilelog', 'backgroundprefetch') + ensurestart = repo.ui.configbool('devel', 'remotefilelog.ensurestart') if prefetchrevset: ui.status(_("prefetching file contents\n")) revs = scmutil.revrange(repo, [prefetchrevset]) base = repo['.'].rev() if bgprefetch: - repo.backgroundprefetch(prefetchrevset, repack=bgrepack) + repo.backgroundprefetch(prefetchrevset, repack=bgrepack, + ensurestart=ensurestart) else: repo.prefetch(revs, base=base) if bgrepack: - repackmod.backgroundrepack(repo, incremental=True) + repackmod.backgroundrepack(repo, incremental=True, + ensurestart=ensurestart) elif bgrepack: - repackmod.backgroundrepack(repo, incremental=True) + repackmod.backgroundrepack(repo, incremental=True, + ensurestart=ensurestart) return result @@ -1085,9 +1091,12 @@ revs = scmutil.revrange(repo, opts.get('rev')) repo.prefetch(revs, opts.get('base'), pats, opts) + ensurestart = repo.ui.configbool('devel', 'remotefilelog.ensurestart') + # Run repack in background if opts.get('repack'): - repackmod.backgroundrepack(repo, incremental=True) + repackmod.backgroundrepack(repo, incremental=True, + ensurestart=ensurestart) @command('repack', [ ('', 'background', None, _('run in a background process'), None), @@ -1096,8 +1105,10 @@ ], _('hg repack [OPTIONS]')) def repack_(ui, repo, *pats, **opts): if opts.get(r'background'): + ensurestart = repo.ui.configbool('devel', 'remotefilelog.ensurestart') repackmod.backgroundrepack(repo, incremental=opts.get(r'incremental'), - packsonly=opts.get(r'packsonly', False)) + packsonly=opts.get(r'packsonly', False), + ensurestart=ensurestart) return options = {'packsonly': opts.get(r'packsonly')} diff -r ce6797ef6eab -r 2c74337e6483 hgext/remotefilelog/repack.py --- a/hgext/remotefilelog/repack.py Sat Aug 31 14:12:38 2019 +0900 +++ b/hgext/remotefilelog/repack.py Wed Aug 28 16:01:16 2019 +0200 @@ -34,7 +34,8 @@ class RepackAlreadyRunning(error.Abort): pass -def backgroundrepack(repo, incremental=True, packsonly=False): +def backgroundrepack(repo, incremental=True, packsonly=False, + ensurestart=False): cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'repack'] msg = _("(running background repack)\n") if incremental: @@ -44,7 +45,7 @@ cmd.append('--packsonly') repo.ui.warn(msg) # We know this command will find a binary, so don't block on it starting. - procutil.runbgcommand(cmd, encoding.environ, ensurestart=False) + procutil.runbgcommand(cmd, encoding.environ, ensurestart=ensurestart) def fullrepack(repo, options=None): """If ``packsonly`` is True, stores creating only loose objects are skipped. diff -r ce6797ef6eab -r 2c74337e6483 hgext/remotefilelog/shallowrepo.py --- a/hgext/remotefilelog/shallowrepo.py Sat Aug 31 14:12:38 2019 +0900 +++ b/hgext/remotefilelog/shallowrepo.py Wed Aug 28 16:01:16 2019 +0200 @@ -183,7 +183,7 @@ origctx=origctx) def backgroundprefetch(self, revs, base=None, repack=False, pats=None, - opts=None): + opts=None, ensurestart=False): """Runs prefetch in background with optional repack """ cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'prefetch'] @@ -193,7 +193,8 @@ cmd += ['-r', revs] # We know this command will find a binary, so don't block # on it starting. - procutil.runbgcommand(cmd, encoding.environ, ensurestart=False) + procutil.runbgcommand(cmd, encoding.environ, + ensurestart=ensurestart) def prefetch(self, revs, base=None, pats=None, opts=None): """Prefetches all the necessary file revisions for the given revs diff -r ce6797ef6eab -r 2c74337e6483 tests/test-remotefilelog-bgprefetch.t --- a/tests/test-remotefilelog-bgprefetch.t Sat Aug 31 14:12:38 2019 +0900 +++ b/tests/test-remotefilelog-bgprefetch.t Wed Aug 28 16:01:16 2019 +0200 @@ -1,6 +1,12 @@ #require no-windows $ . "$TESTDIR/remotefilelog-library.sh" +# devel.remotefilelog.ensurestart: reduce race condition with +# waiton{repack/prefetch} + $ cat >> $HGRCPATH < [devel] + > remotefilelog.ensurestart=True + > EOF $ hg init master $ cd master diff -r ce6797ef6eab -r 2c74337e6483 tests/test-remotefilelog-repack-fast.t --- a/tests/test-remotefilelog-repack-fast.t Sat Aug 31 14:12:38 2019 +0900 +++ b/tests/test-remotefilelog-repack-fast.t Wed Aug 28 16:01:16 2019 +0200 @@ -1,10 +1,13 @@ #require no-windows $ . "$TESTDIR/remotefilelog-library.sh" - +# devel.remotefilelog.ensurestart: reduce race condition with +# waiton{repack/prefetch} $ cat >> $HGRCPATH < [remotefilelog] > fastdatapack=True + > [devel] + > remotefilelog.ensurestart=True > EOF $ hg init master diff -r ce6797ef6eab -r 2c74337e6483 tests/test-remotefilelog-repack.t --- a/tests/test-remotefilelog-repack.t Sat Aug 31 14:12:38 2019 +0900 +++ b/tests/test-remotefilelog-repack.t Wed Aug 28 16:01:16 2019 +0200 @@ -1,6 +1,12 @@ #require no-windows $ . "$TESTDIR/remotefilelog-library.sh" +# devel.remotefilelog.ensurestart: reduce race condition with +# waiton{repack/prefetch} + $ cat >> $HGRCPATH < [devel] + > remotefilelog.ensurestart=True + > EOF $ hg init master $ cd master