# HG changeset patch # User Georges Racinet # Date 2019-05-21 15:44:15 # Node ID 334c1ea571364b07e59b2a18dd7e46978d2174d3 # Parent 4e7bd6180b535eea6cc0b2415738edce938c6471 discovery: new devel.discovery.randomize option By default, this is True, but setting it to False is a uniform way to kill all randomness in integration tests such as test-setdiscovery.t By "uniform" we mean that it can be passed to implementations in other languages, for which the monkey-patching of random.sample would be irrelevant. In the above mentioned test file, we use it right away, replacing the adhoc extension that had the same purpose, and to derandomize a case with many round-trips, that we'll need to behave uniformly in the Rust version. Differential Revision: https://phab.mercurial-scm.org/D6427 diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -415,6 +415,9 @@ coreconfigitem('devel', 'debug.extension coreconfigitem('devel', 'debug.peer-request', default=False, ) +coreconfigitem('devel', 'discovery.randomize', + default=True, +) _registerdiffopts(section='diff') coreconfigitem('email', 'bcc', default=None, diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py --- a/mercurial/setdiscovery.py +++ b/mercurial/setdiscovery.py @@ -390,7 +390,9 @@ def findcommonheads(ui, local, remote, # full blown discovery - disco = partialdiscovery(local, ownheads, remote.limitedarguments) + randomize = ui.configbool('devel', 'discovery.randomize') + disco = partialdiscovery(local, ownheads, remote.limitedarguments, + randomize=randomize) # treat remote heads (and maybe own heads) as a first implicit sample # response disco.addcommons(knownsrvheads) diff --git a/tests/test-setdiscovery.t b/tests/test-setdiscovery.t --- a/tests/test-setdiscovery.t +++ b/tests/test-setdiscovery.t @@ -968,7 +968,7 @@ One with >200 heads. We now switch to se updating to branch b 0 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg -R a debugdiscovery b --debug --verbose --config progress.debug=true + $ hg -R a debugdiscovery b --debug --verbose --config progress.debug=true --config devel.discovery.randomize=false comparing with b query 1; heads searching for changes @@ -980,13 +980,14 @@ One with >200 heads. We now switch to se query 3; still undecided: 980, sample size is: 200 sampling from both directions searching: 4 queries - query 4; still undecided: 435, sample size is: 210 (no-py3 !) - query 4; still undecided: 430, sample size is: 210 (py3 !) + query 4; still undecided: 497, sample size is: 210 sampling from both directions searching: 5 queries - query 5; still undecided: 185, sample size is: 185 (no-py3 !) - query 5; still undecided: 187, sample size is: 187 (py3 !) - 5 total queries in *.????s (glob) + query 5; still undecided: 285, sample size is: 220 + sampling from both directions + searching: 6 queries + query 6; still undecided: 63, sample size is: 63 + 6 total queries in *.????s (glob) elapsed time: * seconds (glob) heads summary: total common heads: 1 @@ -1095,16 +1096,9 @@ The case where all the 'initialsamplesiz give 'all remote heads known locally' without checking the remaining heads - fixed in 86c35b7ae300: - $ cat >> $TESTTMP/unrandomsample.py << EOF - > import random - > def sample(population, k): - > return sorted(population)[:k] - > random.sample = sample - > EOF - $ cat >> r1/.hg/hgrc << EOF - > [extensions] - > unrandomsample = $TESTTMP/unrandomsample.py + > [devel] + > discovery.randomize = False > EOF $ hg -R r1 outgoing r2 -T'{rev} ' --config extensions.blackbox= \