annotate tests/get-with-headers.py @ 41979:0d467e4de4ae

discovery: fix embarrassing typo in slice definition The code introduced in e514799e4e07 ended up having a silly bug. The indexing selected a single item slice picking only p1. The discovery result was still correct, but the sampling was hampered, sometime leading to much more round trips being performed. Fixing this issue restore the previous sampling behavior. This fix has a negative performance impact on the pathological case the previous test has been built. # parent of this changesets ! wall 5.313884 comb 5.310000 user 5.260000 sys 0.050000 (best of 5) ! wall 6.711860 comb 6.710000 user 6.670000 sys 0.040000 (max of 5) ! wall 5.844016 comb 5.842000 user 5.784000 sys 0.058000 (avg of 5) ! wall 5.778635 comb 5.780000 user 5.740000 sys 0.040000 (median of 5) # With this changesets. ! wall 6.350879 comb 6.350000 user 6.300000 sys 0.050000 (best of 5) ! wall 6.653647 comb 6.660000 user 6.480000 sys 0.180000 (max of 5) ! wall 6.492762 comb 6.494000 user 6.414000 sys 0.080000 (avg of 5) ! wall 6.547577 comb 6.550000 user 6.490000 sys 0.060000 (median of 5) Changeset e514799e4e07 raised the question of using the "_uncheckedparentrevs" instead of the current code. So I ran comparative timing: # old code: 55919b96c02a (e514799e4e07 parent) ! wall 64.078708 comb 64.080000 user 63.160000 sys 0.920000 (best of 5) ! wall 68.296300 comb 68.290000 user 67.410000 sys 0.880000 (max of 5) ! wall 65.899075 comb 65.894000 user 65.082000 sys 0.812000 (avg of 5) ! wall 66.140286 comb 66.130000 user 65.330000 sys 0.800000 (median of 5) # buggy code: e514799e4e07 ! wall 46.605362 comb 46.610000 user 45.880000 sys 0.730000 (best of 5) ! wall 48.619659 comb 48.620000 user 47.890000 sys 0.730000 (max of 5) ! wall 47.350247 comb 47.350000 user 46.672000 sys 0.678000 (avg of 5) ! wall 46.983224 comb 46.980000 user 46.350000 sys 0.630000 (median of 5) # fixed code: e514799e4e07 with this fix ! wall 55.858460 comb 55.850000 user 55.090000 sys 0.760000 (best of 5) ! wall 59.048805 comb 59.060000 user 58.110000 sys 0.950000 (max of 5) ! wall 57.192639 comb 57.192000 user 56.350000 sys 0.842000 (avg of 5) ! wall 57.056373 comb 57.060000 user 56.160000 sys 0.900000 (median of 5) # version using uncheckedparents ! wall 56.471916 comb 56.470000 user 55.630000 sys 0.840000 (best of 5) ! wall 58.228793 comb 58.230000 user 57.600000 sys 0.630000 (max of 5) ! wall 57.377583 comb 57.378000 user 56.674000 sys 0.704000 (avg of 5) ! wall 57.008843 comb 57.010000 user 56.330000 sys 0.680000 (median of 5) So it looks like the overhead from `_uncheckedparentrevs` is not that impactful. I'll investigate this shortly. I'm almost done updating our benchmark suite with more meaningful discovery cases.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 14 Mar 2019 19:13:45 +0000
parents fe11fc7e541f
children 2372284d9457
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2532
84655f721f39 Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff changeset
1 #!/usr/bin/env python
84655f721f39 Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff changeset
2
8447
d5ebcf8f6855 tests: fix doc string in get-with-headers.py
Martin Geisler <mg@lazybytes.net>
parents: 7544
diff changeset
3 """This does HTTP GET requests given a host:port and path and returns
2532
84655f721f39 Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff changeset
4 a subset of the headers plus the body of the result."""
84655f721f39 Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff changeset
5
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
6 from __future__ import absolute_import
27296
8e86679d8acd tests: use absolute_import in /get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25208
diff changeset
7
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
8 import argparse
27296
8e86679d8acd tests: use absolute_import in /get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25208
diff changeset
9 import json
8e86679d8acd tests: use absolute_import in /get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25208
diff changeset
10 import os
8e86679d8acd tests: use absolute_import in /get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25208
diff changeset
11 import sys
7054
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
12
29455
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
13 from mercurial import (
40154
fe11fc7e541f py3: encode JSON str to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36576
diff changeset
14 pycompat,
29455
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
15 util,
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
16 )
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
17
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
18 httplib = util.httplib
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28726
diff changeset
19
7054
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
20 try:
27296
8e86679d8acd tests: use absolute_import in /get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25208
diff changeset
21 import msvcrt
7054
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
22 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
23 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
24 except ImportError:
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
25 pass
e837f2294643 get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5561
diff changeset
26
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
27 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
28
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
29 parser = argparse.ArgumentParser()
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
30 parser.add_argument('--twice', action='store_true')
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
31 parser.add_argument('--headeronly', action='store_true')
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
32 parser.add_argument('--json', action='store_true')
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
33 parser.add_argument('--hgproto')
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
34 parser.add_argument('--requestheader', nargs='*', default=[],
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
35 help='Send an additional HTTP request header. Argument '
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
36 'value is <header>=<value>')
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
37 parser.add_argument('--bodyfile',
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
38 help='Write HTTP response body to a file')
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
39 parser.add_argument('host')
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
40 parser.add_argument('path')
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
41 parser.add_argument('show', nargs='*')
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
42
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
43 args = parser.parse_args()
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
44
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
45 twice = args.twice
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
46 headeronly = args.headeronly
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
47 formatjson = args.json
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
48 hgproto = args.hgproto
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
49 requestheaders = args.requestheader
30764
e75463e3179f protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29455
diff changeset
50
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
51 tag = None
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
52 def request(host, path, show):
17017
953faba28e91 tests: prepare get-with-headers.py for MSYS
Mads Kiilerich <mads@kiilerich.com>
parents: 12250
diff changeset
53 assert not path.startswith('/'), path
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
54 global tag
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
55 headers = {}
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
56 if tag:
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
57 headers['If-None-Match'] = tag
30764
e75463e3179f protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29455
diff changeset
58 if hgproto:
e75463e3179f protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29455
diff changeset
59 headers['X-HgProto-1'] = hgproto
5561
22713dce19f6 hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents: 2532
diff changeset
60
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
61 for header in requestheaders:
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
62 key, value = header.split('=', 1)
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
63 headers[key] = value
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
64
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
65 conn = httplib.HTTPConnection(host)
17017
953faba28e91 tests: prepare get-with-headers.py for MSYS
Mads Kiilerich <mads@kiilerich.com>
parents: 12250
diff changeset
66 conn.request("GET", '/' + path, None, headers)
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
67 response = conn.getresponse()
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
68 stdout.write(b'%d %s\n' % (response.status,
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
69 response.reason.encode('ascii')))
18380
a4d7fd7ad1f7 serve: don't send any content headers with 304 responses
Mads Kiilerich <madski@unity3d.com>
parents: 17017
diff changeset
70 if show[:1] == ['-']:
18393
a38039ef7312 tests: make test-hgweb.t output stable
Mads Kiilerich <madski@unity3d.com>
parents: 18380
diff changeset
71 show = sorted(h for h, v in response.getheaders()
a38039ef7312 tests: make test-hgweb.t output stable
Mads Kiilerich <madski@unity3d.com>
parents: 18380
diff changeset
72 if h.lower() not in show)
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
73 for h in [h.lower() for h in show]:
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
74 if response.getheader(h, None) is not None:
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
75 stdout.write(b"%s: %s\n" % (h.encode('ascii'),
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
76 response.getheader(h).encode('ascii')))
18400
f1118507174b get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18393
diff changeset
77 if not headeronly:
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
78 stdout.write(b'\n')
23409
dc4d2cd3aa3e hgweb: send proper HTTP response after uncaught exception
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19865
diff changeset
79 data = response.read()
24543
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
80
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
81 if args.bodyfile:
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
82 bodyfh = open(args.bodyfile, 'wb')
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
83 else:
36576
cfd0c1df5e33 get-with-headers: use bytes stdout thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 36276
diff changeset
84 bodyfh = stdout
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
85
24543
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
86 # Pretty print JSON. This also has the beneficial side-effect
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
87 # of verifying emitted JSON is well-formed.
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
88 if formatjson:
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
89 # json.dumps() will print trailing newlines. Eliminate them
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
90 # to make tests easier to write.
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
91 data = json.loads(data)
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
92 lines = json.dumps(data, sort_keys=True, indent=2).splitlines()
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
93 for line in lines:
40154
fe11fc7e541f py3: encode JSON str to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36576
diff changeset
94 bodyfh.write(pycompat.sysbytes(line.rstrip()))
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
95 bodyfh.write(b'\n')
24543
747401086a38 get-with-headers: support parsing and pretty printing JSON
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23409
diff changeset
96 else:
35781
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
97 bodyfh.write(data)
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
98
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
99 if args.bodyfile:
c6ef8e841873 tests: teach get-with-headers.py some new tricks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35780
diff changeset
100 bodyfh.close()
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
101
31791
39f6333e968c tests: store ETag when using --headeronly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30764
diff changeset
102 if twice and response.getheader('ETag', None):
39f6333e968c tests: store ETag when using --headeronly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30764
diff changeset
103 tag = response.getheader('ETag')
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
104
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
105 return response.status
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
106
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
107 status = request(args.host, args.path, args.show)
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
108 if twice:
35780
32317f8bbe2a tests: use argparse in get-with-headers.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31791
diff changeset
109 status = request(args.host, args.path, args.show)
12182
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
110
1121af239761 tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10905
diff changeset
111 if 200 <= status <= 305:
5561
22713dce19f6 hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents: 2532
diff changeset
112 sys.exit(0)
22713dce19f6 hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents: 2532
diff changeset
113 sys.exit(1)