Mercurial > hg
comparison tests/test-static-http.t @ 22959:10116463b0b1
tests: pull common http server setup out of individual tests
There are currently two different tests using roughly the same code to
create temporary scripts acting as HTTP servers. As there is going to
be at least one more in an upcoming change, factor those out in a
standalone dumbhttp.py script.
author | Mike Hommey <mh@glandium.org> |
---|---|
date | Thu, 16 Oct 2014 13:48:51 +0900 |
parents | e803186296ab |
children | 7c13c9404c2c |
comparison
equal
deleted
inserted
replaced
22958:bb7a911b138e | 22959:10116463b0b1 |
---|---|
13 [1] | 13 [1] |
14 | 14 |
15 This server doesn't do range requests so it's basically only good for | 15 This server doesn't do range requests so it's basically only good for |
16 one pull | 16 one pull |
17 | 17 |
18 $ cat > dumb.py <<EOF | 18 $ python "$TESTDIR/dumbhttp.py" -p $HGPORT --pid dumb.pid |
19 > import BaseHTTPServer, SimpleHTTPServer, os, signal, sys | |
20 > | |
21 > def run(server_class=BaseHTTPServer.HTTPServer, | |
22 > handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler): | |
23 > server_address = ('localhost', int(os.environ['HGPORT'])) | |
24 > httpd = server_class(server_address, handler_class) | |
25 > httpd.serve_forever() | |
26 > | |
27 > signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0)) | |
28 > fp = file('dumb.pid', 'wb') | |
29 > fp.write(str(os.getpid()) + '\n') | |
30 > fp.close() | |
31 > run() | |
32 > EOF | |
33 $ python dumb.py 2>/dev/null & | |
34 | |
35 Cannot just read $!, it will not be set to the right value on Windows/MinGW | |
36 | |
37 $ cat > wait.py <<EOF | |
38 > import time | |
39 > while True: | |
40 > try: | |
41 > if '\n' in file('dumb.pid', 'rb').read(): | |
42 > break | |
43 > except IOError: | |
44 > pass | |
45 > time.sleep(0.2) | |
46 > EOF | |
47 $ python wait.py | |
48 $ cat dumb.pid >> $DAEMON_PIDS | 19 $ cat dumb.pid >> $DAEMON_PIDS |
49 $ hg init remote | 20 $ hg init remote |
50 $ cd remote | 21 $ cd remote |
51 $ echo foo > bar | 22 $ echo foo > bar |
52 $ echo c2 > '.dotfile with spaces' | 23 $ echo c2 > '.dotfile with spaces' |