tests/test-impexp-branch.t
author Gregory Szorc <gregory.szorc@gmail.com>
Thu, 06 Sep 2018 14:04:46 -0700
changeset 39568 842cd0bdda75
parent 38367 e033fd788bf8
child 39707 5abc47d4ca6b
permissions -rw-r--r--
util: teach lrucachedict to enforce a max total cost Now that lrucachedict entries can have a numeric cost associated with them and we can easily pop the oldest item in the cache, it now becomes relatively trivial to implement support for enforcing a high water mark on the total cost of items in the cache. This commit teaches lrucachedict instances to have a max cost associated with them. When items are inserted, we pop old items until enough "cost" frees up to make room for the new item. This feature is close to zero cost when not used (modulo the insertion regressed introduced by the previous commit): $ ./hg perflrucachedict --size 4 --gets 1000000 --sets 1000000 --mixed 1000000 ! gets ! wall 0.607444 comb 0.610000 user 0.610000 sys 0.000000 (best of 17) ! wall 0.601653 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts ! wall 0.678261 comb 0.680000 user 0.680000 sys 0.000000 (best of 14) ! wall 0.685042 comb 0.680000 user 0.680000 sys 0.000000 (best of 15) ! sets ! wall 0.808770 comb 0.800000 user 0.800000 sys 0.000000 (best of 13) ! wall 0.834241 comb 0.830000 user 0.830000 sys 0.000000 (best of 12) ! mixed ! wall 0.782441 comb 0.780000 user 0.780000 sys 0.000000 (best of 13) ! wall 0.803804 comb 0.800000 user 0.800000 sys 0.000000 (best of 13) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 ! init ! wall 0.006952 comb 0.010000 user 0.010000 sys 0.000000 (best of 418) ! gets ! wall 0.613350 comb 0.610000 user 0.610000 sys 0.000000 (best of 17) ! wall 0.617415 comb 0.620000 user 0.620000 sys 0.000000 (best of 17) ! inserts ! wall 0.701270 comb 0.700000 user 0.700000 sys 0.000000 (best of 15) ! wall 0.700516 comb 0.700000 user 0.700000 sys 0.000000 (best of 15) ! sets ! wall 0.825720 comb 0.830000 user 0.830000 sys 0.000000 (best of 13) ! wall 0.837946 comb 0.840000 user 0.830000 sys 0.010000 (best of 12) ! mixed ! wall 0.821644 comb 0.820000 user 0.820000 sys 0.000000 (best of 13) ! wall 0.850559 comb 0.850000 user 0.850000 sys 0.000000 (best of 12) I reckon the slight slowdown on insert is due to added if checks. For caches with total cost limiting enabled: $ hg perflrucachedict --size 4 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 100 ! gets w/ cost limit ! wall 0.598737 comb 0.590000 user 0.590000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 1.694282 comb 1.700000 user 1.700000 sys 0.000000 (best of 6) ! mixed w/ cost limit ! wall 1.157655 comb 1.150000 user 1.150000 sys 0.000000 (best of 9) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 10000 ! gets w/ cost limit ! wall 0.598526 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 37.838315 comb 37.840000 user 37.840000 sys 0.000000 (best of 3) ! mixed w/ cost limit ! wall 18.060198 comb 18.060000 user 18.060000 sys 0.000000 (best of 3) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 10000 --mixedgetfreq 90 ! gets w/ cost limit ! wall 0.600024 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 37.154547 comb 37.120000 user 37.120000 sys 0.000000 (best of 3) ! mixed w/ cost limit ! wall 4.381602 comb 4.380000 user 4.370000 sys 0.010000 (best of 3) The functions we're benchmarking are slightly different, which could move numbers by a few milliseconds. But the slowdown on insert is too great to be explained by that. The slowness is due to insert heavy operations needing to call popoldest() repeatedly when the cache is at capacity. The next commit will address this. Differential Revision: https://phab.mercurial-scm.org/D4503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16475
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
     1
  $ echo '[extensions]' >> $HGRCPATH
20115
db6b958c4f35 tests: use strip extension instead of mq where it makes sense
Martin Geisler <martin@geisler.net>
parents: 16913
diff changeset
     2
  $ echo 'strip =' >> $HGRCPATH
16475
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
     3
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
     4
  $ cat >findbranch.py <<EOF
33960
4d40fd0283d8 tests: update test-impexp-branch to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 32940
diff changeset
     5
  > from __future__ import absolute_import
4d40fd0283d8 tests: update test-impexp-branch to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 32940
diff changeset
     6
  > import re
4d40fd0283d8 tests: update test-impexp-branch to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 32940
diff changeset
     7
  > import sys
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
     8
  > 
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
     9
  > head_re = re.compile('^#(?:(?:\\s+([A-Za-z][A-Za-z0-9_]*)(?:\\s.*)?)|(?:\\s*))$')
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    10
  > 
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    11
  > for line in sys.stdin:
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    12
  >     hmatch = head_re.match(line)
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    13
  >     if not hmatch:
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    14
  >         sys.exit(1)
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    15
  >     if hmatch.group(1) == 'Branch':
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    16
  >         sys.exit(0)
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    17
  > sys.exit(1)
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    18
  > EOF
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    19
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    20
  $ hg init a
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    21
  $ cd a
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    22
  $ echo "Rev 1" >rev
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    23
  $ hg add rev
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    24
  $ hg commit -m "No branch."
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    25
  $ hg branch abranch
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    26
  marked working directory as branch abranch
15615
41885892796e branch: warn on branching
Matt Mackall <mpm@selenic.com>
parents: 14126
diff changeset
    27
  (branches are permanent and global, did you want a bookmark?)
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    28
  $ echo "Rev  2" >rev
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    29
  $ hg commit -m "With branch."
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    30
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    31
  $ hg export 0 > ../r0.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    32
  $ hg export 1 > ../r1.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    33
  $ cd ..
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    34
32940
75be14993fda cleanup: use $PYTHON to run python in many more tests
Augie Fackler <augie@google.com>
parents: 22485
diff changeset
    35
  $ if $PYTHON findbranch.py < r0.patch; then
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    36
  >     echo "Export of default branch revision has Branch header" 1>&2
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    37
  >     exit 1
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    38
  > fi
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    39
32940
75be14993fda cleanup: use $PYTHON to run python in many more tests
Augie Fackler <augie@google.com>
parents: 22485
diff changeset
    40
  $ if $PYTHON findbranch.py < r1.patch; then
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    41
  >     :  # Do nothing
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    42
  > else
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    43
  >     echo "Export of branch revision is missing Branch header" 1>&2
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    44
  >     exit 1
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    45
  > fi
4442
871ff96a86cc Add a test for the Branch header being in hg export.
Eric Hopper <hopper@omnifarious.org>
parents:
diff changeset
    46
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    47
Make sure import still works with branch information in patches.
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    48
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    49
  $ hg init b
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    50
  $ cd b
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    51
  $ hg import ../r0.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    52
  applying ../r0.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    53
  $ hg import ../r1.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    54
  applying ../r1.patch
12119
46ab8c5dd99a tests: unify test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 4444
diff changeset
    55
  $ cd ..
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    56
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    57
  $ hg init c
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    58
  $ cd c
22485
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    59
  $ hg import --exact --no-commit ../r0.patch
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    60
  applying ../r0.patch
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    61
  warning: can't check exact import with --no-commit
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    62
  $ hg st
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    63
  A rev
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    64
  $ hg revert -a
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    65
  forgetting rev
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 20115
diff changeset
    66
  $ rm rev
14126
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    67
  $ hg import --exact ../r0.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    68
  applying ../r0.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    69
  $ hg import --exact ../r1.patch
fbbe9239574a tests: export patches only once in test-impexp-branch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12119
diff changeset
    70
  applying ../r1.patch
16475
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    71
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    72
Test --exact and patch header separators (issue3356)
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    73
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    74
  $ hg strip --no-backup .
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    75
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    76
  >>> import re
36394
4bc983568016 py3: replace file() with open()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33960
diff changeset
    77
  >>> p = open('../r1.patch', 'rb').read()
38367
e033fd788bf8 py3: make tests/test-impexp-branch.t compatible with Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36394
diff changeset
    78
  >>> p = re.sub(br'Parent\s+', b'Parent ', p)
e033fd788bf8 py3: make tests/test-impexp-branch.t compatible with Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36394
diff changeset
    79
  >>> open('../r1-ws.patch', 'wb').write(p) and None
16475
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    80
  $ hg import --exact ../r1-ws.patch
1f75c1decdeb patch: be more tolerant with "Parent" header (issue3356)
Patrick Mezard <patrick@mezard.eu>
parents: 15615
diff changeset
    81
  applying ../r1-ws.patch
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 16475
diff changeset
    82
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 16475
diff changeset
    83
  $ cd ..