##// END OF EJS Templates
tests: pull common http server setup out of individual tests...
Mike Hommey -
r22959:10116463 default
parent child Browse files
Show More
@@ -0,0 +1,54 b''
1 #!/usr/bin/env python
2
3 """
4 Small and dumb HTTP server for use in tests.
5 """
6
7 from optparse import OptionParser
8 import BaseHTTPServer, SimpleHTTPServer, os, signal, subprocess, sys
9
10
11 def run(server_class=BaseHTTPServer.HTTPServer,
12 handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler,
13 server_address=('localhost', 8000)):
14 httpd = server_class(server_address, handler_class)
15 httpd.serve_forever()
16
17
18 if __name__ == '__main__':
19 parser = OptionParser()
20 parser.add_option('-p', '--port', dest='port', type='int', default=8000,
21 help='TCP port to listen on', metavar='PORT')
22 parser.add_option('-H', '--host', dest='host', default='localhost',
23 help='hostname or IP to listen on', metavar='HOST')
24 parser.add_option('--pid', dest='pid',
25 help='file name where the PID of the server is stored')
26 parser.add_option('-f', '--foreground', dest='foreground',
27 action='store_true',
28 help='do not start the HTTP server in the background')
29
30 (options, args) = parser.parse_args()
31
32 signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0))
33
34 if options.foreground and options.pid:
35 parser.error("options --pid and --foreground are mutually exclusive")
36
37 if options.foreground:
38 run(server_address=(options.host, options.port))
39 else:
40 # This doesn't attempt to cleanly detach the process, as it's not
41 # meant to be a long-lived, independent process. As a consequence,
42 # it's still part of the same process group, and keeps any file
43 # descriptors it might have inherited besided stdin/stdout/stderr.
44 # Trying to do things cleanly is more complicated, requires
45 # OS-dependent code, and is not worth the effort.
46 proc = subprocess.Popen([sys.executable, __file__, '-f',
47 '-H', options.host, '-p', str(options.port)],
48 stdin=open(os.devnull, 'r'),
49 stdout=open(os.devnull, 'w'),
50 stderr=subprocess.STDOUT)
51 if options.pid:
52 fp = file(options.pid, 'wb')
53 fp.write(str(proc.pid) + '\n')
54 fp.close()
@@ -1,33 +1,21 b''
1 #require serve
1 #require serve killdaemons
2
2
3 #if windows
3 #if windows
4 $ hg clone http://localhost:$HGPORT/ copy
4 $ hg clone http://localhost:$HGPORT/ copy
5 abort: * (glob)
5 abort: * (glob)
6 [255]
6 [255]
7 #else
7 #else
8 $ hg clone http://localhost:$HGPORT/ copy
8 $ hg clone http://localhost:$HGPORT/ copy
9 abort: error: Connection refused
9 abort: error: Connection refused
10 [255]
10 [255]
11 #endif
11 #endif
12
12
13 $ test -d copy
13 $ test -d copy
14 [1]
14 [1]
15
15
16 $ cat > dumb.py <<EOF
16 $ python "$TESTDIR/dumbhttp.py" -p $HGPORT --pid dumb.pid
17 > import BaseHTTPServer, SimpleHTTPServer, os, signal
17 $ cat dumb.pid >> $DAEMON_PIDS
18 > def run(server_class=BaseHTTPServer.HTTPServer,
19 > handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
20 > server_address = ('localhost', int(os.environ['HGPORT']))
21 > httpd = server_class(server_address, handler_class)
22 > open("listening", "w")
23 > httpd.handle_request()
24 > run()
25 > EOF
26
27 $ python dumb.py 2> log &
28 $ P=$!
29 $ while [ ! -f listening ]; do sleep 0; done
30 $ hg clone http://localhost:$HGPORT/foo copy2
18 $ hg clone http://localhost:$HGPORT/foo copy2
31 abort: HTTP Error 404: * (glob)
19 abort: HTTP Error 404: * (glob)
32 [255]
20 [255]
33 $ wait $P
21 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
@@ -1,191 +1,162 b''
1 #require killdaemons
1 #require killdaemons
2
2
3 #if windows
3 #if windows
4 $ hg clone http://localhost:$HGPORT/ copy
4 $ hg clone http://localhost:$HGPORT/ copy
5 abort: * (glob)
5 abort: * (glob)
6 [255]
6 [255]
7 #else
7 #else
8 $ hg clone http://localhost:$HGPORT/ copy
8 $ hg clone http://localhost:$HGPORT/ copy
9 abort: error: Connection refused
9 abort: error: Connection refused
10 [255]
10 [255]
11 #endif
11 #endif
12 $ test -d copy
12 $ test -d copy
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'
53 $ hg add
24 $ hg add
54 adding .dotfile with spaces
25 adding .dotfile with spaces
55 adding bar
26 adding bar
56 $ hg commit -m"test"
27 $ hg commit -m"test"
57 $ hg tip
28 $ hg tip
58 changeset: 0:02770d679fb8
29 changeset: 0:02770d679fb8
59 tag: tip
30 tag: tip
60 user: test
31 user: test
61 date: Thu Jan 01 00:00:00 1970 +0000
32 date: Thu Jan 01 00:00:00 1970 +0000
62 summary: test
33 summary: test
63
34
64 $ cd ..
35 $ cd ..
65 $ hg clone static-http://localhost:$HGPORT/remote local
36 $ hg clone static-http://localhost:$HGPORT/remote local
66 requesting all changes
37 requesting all changes
67 adding changesets
38 adding changesets
68 adding manifests
39 adding manifests
69 adding file changes
40 adding file changes
70 added 1 changesets with 2 changes to 2 files
41 added 1 changesets with 2 changes to 2 files
71 updating to branch default
42 updating to branch default
72 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
43 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
73 $ cd local
44 $ cd local
74 $ hg verify
45 $ hg verify
75 checking changesets
46 checking changesets
76 checking manifests
47 checking manifests
77 crosschecking files in changesets and manifests
48 crosschecking files in changesets and manifests
78 checking files
49 checking files
79 2 files, 1 changesets, 2 total revisions
50 2 files, 1 changesets, 2 total revisions
80 $ cat bar
51 $ cat bar
81 foo
52 foo
82 $ cd ../remote
53 $ cd ../remote
83 $ echo baz > quux
54 $ echo baz > quux
84 $ hg commit -A -mtest2
55 $ hg commit -A -mtest2
85 adding quux
56 adding quux
86
57
87 check for HTTP opener failures when cachefile does not exist
58 check for HTTP opener failures when cachefile does not exist
88
59
89 $ rm .hg/cache/*
60 $ rm .hg/cache/*
90 $ cd ../local
61 $ cd ../local
91 $ echo '[hooks]' >> .hg/hgrc
62 $ echo '[hooks]' >> .hg/hgrc
92 $ echo "changegroup = python \"$TESTDIR/printenv.py\" changegroup" >> .hg/hgrc
63 $ echo "changegroup = python \"$TESTDIR/printenv.py\" changegroup" >> .hg/hgrc
93 $ hg pull
64 $ hg pull
94 pulling from static-http://localhost:$HGPORT/remote
65 pulling from static-http://localhost:$HGPORT/remote
95 searching for changes
66 searching for changes
96 adding changesets
67 adding changesets
97 adding manifests
68 adding manifests
98 adding file changes
69 adding file changes
99 added 1 changesets with 1 changes to 1 files
70 added 1 changesets with 1 changes to 1 files
100 changegroup hook: HG_NODE=4ac2e3648604439c580c69b09ec9d93a88d93432 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=http://localhost:$HGPORT/remote
71 changegroup hook: HG_NODE=4ac2e3648604439c580c69b09ec9d93a88d93432 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=http://localhost:$HGPORT/remote
101 (run 'hg update' to get a working copy)
72 (run 'hg update' to get a working copy)
102
73
103 trying to push
74 trying to push
104
75
105 $ hg update
76 $ hg update
106 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
77 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
107 $ echo more foo >> bar
78 $ echo more foo >> bar
108 $ hg commit -m"test"
79 $ hg commit -m"test"
109 $ hg push
80 $ hg push
110 pushing to static-http://localhost:$HGPORT/remote
81 pushing to static-http://localhost:$HGPORT/remote
111 abort: destination does not support push
82 abort: destination does not support push
112 [255]
83 [255]
113
84
114 trying clone -r
85 trying clone -r
115
86
116 $ cd ..
87 $ cd ..
117 $ hg clone -r doesnotexist static-http://localhost:$HGPORT/remote local0
88 $ hg clone -r doesnotexist static-http://localhost:$HGPORT/remote local0
118 abort: unknown revision 'doesnotexist'!
89 abort: unknown revision 'doesnotexist'!
119 [255]
90 [255]
120 $ hg clone -r 0 static-http://localhost:$HGPORT/remote local0
91 $ hg clone -r 0 static-http://localhost:$HGPORT/remote local0
121 adding changesets
92 adding changesets
122 adding manifests
93 adding manifests
123 adding file changes
94 adding file changes
124 added 1 changesets with 2 changes to 2 files
95 added 1 changesets with 2 changes to 2 files
125 updating to branch default
96 updating to branch default
126 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
97 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
127
98
128 test with "/" URI (issue747) and subrepo
99 test with "/" URI (issue747) and subrepo
129
100
130 $ hg init
101 $ hg init
131 $ hg init sub
102 $ hg init sub
132 $ touch sub/test
103 $ touch sub/test
133 $ hg -R sub commit -A -m "test"
104 $ hg -R sub commit -A -m "test"
134 adding test
105 adding test
135 $ hg -R sub tag not-empty
106 $ hg -R sub tag not-empty
136 $ echo sub=sub > .hgsub
107 $ echo sub=sub > .hgsub
137 $ echo a > a
108 $ echo a > a
138 $ hg add a .hgsub
109 $ hg add a .hgsub
139 $ hg -q ci -ma
110 $ hg -q ci -ma
140 $ hg clone static-http://localhost:$HGPORT/ local2
111 $ hg clone static-http://localhost:$HGPORT/ local2
141 requesting all changes
112 requesting all changes
142 adding changesets
113 adding changesets
143 adding manifests
114 adding manifests
144 adding file changes
115 adding file changes
145 added 1 changesets with 3 changes to 3 files
116 added 1 changesets with 3 changes to 3 files
146 updating to branch default
117 updating to branch default
147 cloning subrepo sub from static-http://localhost:$HGPORT/sub
118 cloning subrepo sub from static-http://localhost:$HGPORT/sub
148 requesting all changes
119 requesting all changes
149 adding changesets
120 adding changesets
150 adding manifests
121 adding manifests
151 adding file changes
122 adding file changes
152 added 2 changesets with 2 changes to 2 files
123 added 2 changesets with 2 changes to 2 files
153 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
124 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
154 $ cd local2
125 $ cd local2
155 $ hg verify
126 $ hg verify
156 checking changesets
127 checking changesets
157 checking manifests
128 checking manifests
158 crosschecking files in changesets and manifests
129 crosschecking files in changesets and manifests
159 checking files
130 checking files
160 3 files, 1 changesets, 3 total revisions
131 3 files, 1 changesets, 3 total revisions
161 $ cat a
132 $ cat a
162 a
133 a
163 $ hg paths
134 $ hg paths
164 default = static-http://localhost:$HGPORT/
135 default = static-http://localhost:$HGPORT/
165
136
166 test with empty repo (issue965)
137 test with empty repo (issue965)
167
138
168 $ cd ..
139 $ cd ..
169 $ hg init remotempty
140 $ hg init remotempty
170 $ hg clone static-http://localhost:$HGPORT/remotempty local3
141 $ hg clone static-http://localhost:$HGPORT/remotempty local3
171 no changes found
142 no changes found
172 updating to branch default
143 updating to branch default
173 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
144 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
174 $ cd local3
145 $ cd local3
175 $ hg verify
146 $ hg verify
176 checking changesets
147 checking changesets
177 checking manifests
148 checking manifests
178 crosschecking files in changesets and manifests
149 crosschecking files in changesets and manifests
179 checking files
150 checking files
180 0 files, 0 changesets, 0 total revisions
151 0 files, 0 changesets, 0 total revisions
181 $ hg paths
152 $ hg paths
182 default = static-http://localhost:$HGPORT/remotempty
153 default = static-http://localhost:$HGPORT/remotempty
183
154
184 test with non-repo
155 test with non-repo
185
156
186 $ cd ..
157 $ cd ..
187 $ mkdir notarepo
158 $ mkdir notarepo
188 $ hg clone static-http://localhost:$HGPORT/notarepo local3
159 $ hg clone static-http://localhost:$HGPORT/notarepo local3
189 abort: 'http://localhost:$HGPORT/notarepo' does not appear to be an hg repository!
160 abort: 'http://localhost:$HGPORT/notarepo' does not appear to be an hg repository!
190 [255]
161 [255]
191 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
162 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
General Comments 0
You need to be logged in to leave comments. Login now