Mercurial > hg
annotate tests/dumbhttp.py @ 31971:73e9328e5307
obsolescence: add test case D-3 for obsolescence markers exchange
About 3 years ago, in August 2014, the logic to select what markers to select on
push was ported from the evolve extension to Mercurial core. However, for some
unclear reasons, the tests for that logic were not ported alongside.
I realised it a couple of weeks ago while working on another push related issue.
I've made a clean up pass on the tests and they are now ready to integrate the
core test suite. This series of changesets do not change any logic. I just adds
test for logic that has been around for about 10 versions of Mercurial.
They are a patch for each test case. It makes it easier to review and postpone
one with documentation issues without rejecting the wholes series.
This patch introduce case D3: missing prune target (prune not in "pushed set")
Each test case comes it in own test file. It help parallelism and does not
introduce a significant overhead from having a single unified giant test file.
Here are timing to support this claim.
# Multiple test files version:
# run-tests.py --local -j 1 test-exchange-*.t
53.40s user 6.82s system 85% cpu 1:10.76 total
52.79s user 6.97s system 85% cpu 1:09.97 total
52.94s user 6.82s system 85% cpu 1:09.69 total
# Single test file version:
# run-tests.py --local -j 1 test-exchange-obsmarkers.t
52.97s user 6.85s system 85% cpu 1:10.10 total
52.64s user 6.79s system 85% cpu 1:09.63 total
53.70s user 7.00s system 85% cpu 1:11.17 total
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 10 Apr 2017 16:54:43 +0200 |
parents | d05fefbb5ab3 |
children | 8b95e420e248 |
rev | line source |
---|---|
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
2 |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
3 from __future__ import absolute_import |
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
4 |
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
5 """ |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
6 Small and dumb HTTP server for use in tests. |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
7 """ |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
8 |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
9 import optparse |
31004
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
10 import os |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
11 import signal |
31004
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
12 import socket |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
13 import sys |
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
14 |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
15 from mercurial import ( |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29566
diff
changeset
|
16 server, |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28771
diff
changeset
|
17 util, |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
18 ) |
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
19 |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28771
diff
changeset
|
20 httpserver = util.httpserver |
27282
0bb8c405a7c7
tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23136
diff
changeset
|
21 OptionParser = optparse.OptionParser |
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
22 |
31004
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
23 if os.environ.get('HGIPV6', '0') == '1': |
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
24 class simplehttpserver(httpserver.httpserver): |
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
25 address_family = socket.AF_INET6 |
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
26 else: |
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
27 simplehttpserver = httpserver.httpserver |
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
28 |
23136
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
29 class simplehttpservice(object): |
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
30 def __init__(self, host, port): |
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
31 self.address = (host, port) |
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
32 def init(self): |
31004
d05fefbb5ab3
dumbhttp: use IPv6 if HGIPV6 is set to 1
Jun Wu <quark@fb.com>
parents:
30506
diff
changeset
|
33 self.httpd = simplehttpserver( |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28771
diff
changeset
|
34 self.address, httpserver.simplehttprequesthandler) |
23136
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
35 def run(self): |
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
36 self.httpd.serve_forever() |
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
37 |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
38 if __name__ == '__main__': |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
39 parser = OptionParser() |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
40 parser.add_option('-p', '--port', dest='port', type='int', default=8000, |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
41 help='TCP port to listen on', metavar='PORT') |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
42 parser.add_option('-H', '--host', dest='host', default='localhost', |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
43 help='hostname or IP to listen on', metavar='HOST') |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
44 parser.add_option('--pid', dest='pid', |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
45 help='file name where the PID of the server is stored') |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
46 parser.add_option('-f', '--foreground', dest='foreground', |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
47 action='store_true', |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
48 help='do not start the HTTP server in the background') |
28451
c90cfe76e024
serve: accept multiple values for --daemon-postexec
Jun Wu <quark@fb.com>
parents:
28194
diff
changeset
|
49 parser.add_option('--daemon-postexec', action='append') |
22959
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
50 |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
51 (options, args) = parser.parse_args() |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
52 |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
53 signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0)) |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
54 |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
55 if options.foreground and options.pid: |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
56 parser.error("options --pid and --foreground are mutually exclusive") |
10116463b0b1
tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff
changeset
|
57 |
23136
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
58 opts = {'pid_file': options.pid, |
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
59 'daemon': not options.foreground, |
28194
7623ba92af72
serve: rename --daemon-pipefds to --daemon-postexec (BC)
Jun Wu <quark@fb.com>
parents:
27282
diff
changeset
|
60 'daemon_postexec': options.daemon_postexec} |
23136
6eab50a34fed
tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents:
22959
diff
changeset
|
61 service = simplehttpservice(options.host, options.port) |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29566
diff
changeset
|
62 server.runservice(opts, initfn=service.init, runfn=service.run, |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29566
diff
changeset
|
63 runargs=[sys.executable, __file__] + sys.argv[1:]) |