##// END OF EJS Templates
tests: add killdaemons helper script
Matt Mackall -
r7344:58fd3c71 default
parent child Browse files
Show More
@@ -0,0 +1,25 b''
1 #!/usr/bin/env python
2
3 import os, sys, time, errno, signal
4
5 # Kill off any leftover daemon processes
6 try:
7 fp = file(os.environ['DAEMON_PIDS'])
8 for line in fp:
9 try:
10 pid = int(line)
11 except ValueError:
12 continue
13 try:
14 os.kill(pid, 0)
15 os.kill(pid, signal.SIGTERM)
16 for i in range(10):
17 time.sleep(0.05)
18 os.kill(pid, 0)
19 os.kill(pid, signal.SIGKILL)
20 except OSError, err:
21 if err.errno != errno.ESRCH:
22 raise
23 fp.close()
24 except IOError:
25 pass
@@ -1,116 +1,118 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 mkdir test
3 mkdir test
4 cd test
4 cd test
5 hg init
5 hg init
6 echo foo>foo
6 echo foo>foo
7 hg commit -Am 1 -d '1 0'
7 hg commit -Am 1 -d '1 0'
8 echo bar>bar
8 echo bar>bar
9 hg commit -Am 2 -d '2 0'
9 hg commit -Am 2 -d '2 0'
10 mkdir baz
10 mkdir baz
11 echo bletch>baz/bletch
11 echo bletch>baz/bletch
12 hg commit -Am 3 -d '1000000000 0'
12 hg commit -Am 3 -d '1000000000 0'
13 echo "[web]" >> .hg/hgrc
13 echo "[web]" >> .hg/hgrc
14 echo "name = test-archive" >> .hg/hgrc
14 echo "name = test-archive" >> .hg/hgrc
15 cp .hg/hgrc .hg/hgrc-base
15 cp .hg/hgrc .hg/hgrc-base
16
16
17 # check http return codes
17 # check http return codes
18 test_archtype() {
18 test_archtype() {
19 echo "allow_archive = $1" >> .hg/hgrc
19 echo "allow_archive = $1" >> .hg/hgrc
20 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
20 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
21 cat hg.pid >> $DAEMON_PIDS
21 cat hg.pid >> $DAEMON_PIDS
22 echo % $1 allowed should give 200
22 echo % $1 allowed should give 200
23 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$2" | head -n 1
23 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$2" | head -n 1
24 echo % $3 and $4 disallowed should both give 403
24 echo % $3 and $4 disallowed should both give 403
25 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$3" | head -n 1
25 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$3" | head -n 1
26 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$4" | head -n 1
26 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$4" | head -n 1
27 kill `cat hg.pid`
27 "$TESTDIR/killdaemons.py"
28 cat errors.log
28 cat errors.log
29 cp .hg/hgrc-base .hg/hgrc
29 cp .hg/hgrc-base .hg/hgrc
30 }
30 }
31
31
32 echo
32 echo
33 test_archtype gz tar.gz tar.bz2 zip
33 test_archtype gz tar.gz tar.bz2 zip
34 test_archtype bz2 tar.bz2 zip tar.gz
34 test_archtype bz2 tar.bz2 zip tar.gz
35 test_archtype zip zip tar.gz tar.bz2
35 test_archtype zip zip tar.gz tar.bz2
36
36
37 echo "allow_archive = gz bz2 zip" >> .hg/hgrc
37 echo "allow_archive = gz bz2 zip" >> .hg/hgrc
38 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
38 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
39 cat hg.pid >> $DAEMON_PIDS
39 cat hg.pid >> $DAEMON_PIDS
40
40
41 echo % invalid arch type should give 404
41 echo % invalid arch type should give 404
42 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.invalid" | head -n 1
42 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.invalid" | head -n 1
43 echo
43 echo
44
44
45 TIP=`hg id -v | cut -f1 -d' '`
45 TIP=`hg id -v | cut -f1 -d' '`
46 QTIP=`hg id -q`
46 QTIP=`hg id -q`
47 cat > getarchive.py <<EOF
47 cat > getarchive.py <<EOF
48 import os, sys, urllib2
48 import os, sys, urllib2
49 try:
49 try:
50 # Set stdout to binary mode for win32 platforms
50 # Set stdout to binary mode for win32 platforms
51 import msvcrt
51 import msvcrt
52 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
52 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
53 except ImportError:
53 except ImportError:
54 pass
54 pass
55
55
56 node, archive = sys.argv[1:]
56 node, archive = sys.argv[1:]
57 f = urllib2.urlopen('http://127.0.0.1:%s/?cmd=archive;node=%s;type=%s'
57 f = urllib2.urlopen('http://127.0.0.1:%s/?cmd=archive;node=%s;type=%s'
58 % (os.environ['HGPORT'], node, archive))
58 % (os.environ['HGPORT'], node, archive))
59 sys.stdout.write(f.read())
59 sys.stdout.write(f.read())
60 EOF
60 EOF
61 http_proxy= python getarchive.py "$TIP" gz | gunzip | tar tf - | sed "s/$QTIP/TIP/"
61 http_proxy= python getarchive.py "$TIP" gz | gunzip | tar tf - | sed "s/$QTIP/TIP/"
62 http_proxy= python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - | sed "s/$QTIP/TIP/"
62 http_proxy= python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - | sed "s/$QTIP/TIP/"
63 http_proxy= python getarchive.py "$TIP" zip > archive.zip
63 http_proxy= python getarchive.py "$TIP" zip > archive.zip
64 unzip -t archive.zip | sed "s/$QTIP/TIP/"
64 unzip -t archive.zip | sed "s/$QTIP/TIP/"
65
65
66 "$TESTDIR/killdaemons.py"
67
66 hg archive -t tar test.tar
68 hg archive -t tar test.tar
67 tar tf test.tar
69 tar tf test.tar
68
70
69 hg archive -t tbz2 -X baz test.tar.bz2
71 hg archive -t tbz2 -X baz test.tar.bz2
70 bunzip2 -dc test.tar.bz2 | tar tf -
72 bunzip2 -dc test.tar.bz2 | tar tf -
71
73
72 hg archive -t tgz -p %b-%h test-%h.tar.gz
74 hg archive -t tgz -p %b-%h test-%h.tar.gz
73 gzip -dc test-$QTIP.tar.gz | tar tf - | sed "s/$QTIP/TIP/"
75 gzip -dc test-$QTIP.tar.gz | tar tf - | sed "s/$QTIP/TIP/"
74
76
75 cat > md5comp.py <<EOF
77 cat > md5comp.py <<EOF
76 from mercurial.util import md5
78 from mercurial.util import md5
77 import sys
79 import sys
78 f1, f2 = sys.argv[1:3]
80 f1, f2 = sys.argv[1:3]
79 h1 = md5(file(f1, 'rb').read()).hexdigest()
81 h1 = md5(file(f1, 'rb').read()).hexdigest()
80 h2 = md5(file(f2, 'rb').read()).hexdigest()
82 h2 = md5(file(f2, 'rb').read()).hexdigest()
81 print h1 == h2 or "md5 differ: " + repr((h1, h2))
83 print h1 == h2 or "md5 differ: " + repr((h1, h2))
82 EOF
84 EOF
83
85
84 # archive name is stored in the archive, so create similar
86 # archive name is stored in the archive, so create similar
85 # archives and rename them afterwards.
87 # archives and rename them afterwards.
86 hg archive -t tgz tip.tar.gz
88 hg archive -t tgz tip.tar.gz
87 mv tip.tar.gz tip1.tar.gz
89 mv tip.tar.gz tip1.tar.gz
88 sleep 1
90 sleep 1
89 hg archive -t tgz tip.tar.gz
91 hg archive -t tgz tip.tar.gz
90 mv tip.tar.gz tip2.tar.gz
92 mv tip.tar.gz tip2.tar.gz
91 python md5comp.py tip1.tar.gz tip2.tar.gz
93 python md5comp.py tip1.tar.gz tip2.tar.gz
92
94
93 hg archive -t zip -p /illegal test.zip
95 hg archive -t zip -p /illegal test.zip
94 hg archive -t zip -p very/../bad test.zip
96 hg archive -t zip -p very/../bad test.zip
95
97
96 hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
98 hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
97 unzip -t test.zip
99 unzip -t test.zip
98
100
99 hg archive -t tar - | tar tf - | sed "s/$QTIP/TIP/"
101 hg archive -t tar - | tar tf - | sed "s/$QTIP/TIP/"
100
102
101 hg archive -r 0 -t tar rev-%r.tar
103 hg archive -r 0 -t tar rev-%r.tar
102 if [ -f rev-0.tar ]; then
104 if [ -f rev-0.tar ]; then
103 echo 'rev-0.tar created'
105 echo 'rev-0.tar created'
104 fi
106 fi
105
107
106 hg archive -t bogus test.bogus
108 hg archive -t bogus test.bogus
107
109
108 echo % server errors
110 echo % server errors
109 cat errors.log
111 cat errors.log
110
112
111 echo '% empty repo'
113 echo '% empty repo'
112 hg init ../empty
114 hg init ../empty
113 cd ../empty
115 cd ../empty
114 hg archive ../test-empty
116 hg archive ../test-empty
115
117
116 exit 0
118 exit 0
@@ -1,172 +1,175 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 # adjust to non-default HGPORT, e.g. with run-tests.py -j
3 # adjust to non-default HGPORT, e.g. with run-tests.py -j
4 hideport() { sed "s/localhost:$HGPORT/localhost:20059/"; }
4 hideport() { sed "s/localhost:$HGPORT/localhost:20059/"; }
5 hidehash() { sed "s/changeset 3:............ merges/changeset 3:... merges/"; }
5 hidehash() { sed "s/changeset 3:............ merges/changeset 3:... merges/"; }
6
6
7 echo "[extensions]" >> $HGRCPATH
7 echo "[extensions]" >> $HGRCPATH
8 echo "fetch=" >> $HGRCPATH
8 echo "fetch=" >> $HGRCPATH
9
9
10 echo % test fetch with default branches only
10 echo % test fetch with default branches only
11 hg init a
11 hg init a
12 echo a > a/a
12 echo a > a/a
13 hg --cwd a commit -d '1 0' -Ama
13 hg --cwd a commit -d '1 0' -Ama
14
14
15 hg clone a b
15 hg clone a b
16 hg clone a c
16 hg clone a c
17
17
18 echo b > a/b
18 echo b > a/b
19 hg --cwd a commit -d '2 0' -Amb
19 hg --cwd a commit -d '2 0' -Amb
20 hg --cwd a parents -q
20 hg --cwd a parents -q
21
21
22 echo % should pull one change
22 echo % should pull one change
23 hg --cwd b fetch ../a
23 hg --cwd b fetch ../a
24 hg --cwd b parents -q
24 hg --cwd b parents -q
25
25
26 echo c > c/c
26 echo c > c/c
27 hg --cwd c commit -d '3 0' -Amc
27 hg --cwd c commit -d '3 0' -Amc
28
28
29 hg clone c d
29 hg clone c d
30 hg clone c e
30 hg clone c e
31
31
32 # We cannot use the default commit message if fetching from a local
32 # We cannot use the default commit message if fetching from a local
33 # repo, because the path of the repo will be included in the commit
33 # repo, because the path of the repo will be included in the commit
34 # message, making every commit appear different.
34 # message, making every commit appear different.
35
35
36 echo % should merge c into a
36 echo % should merge c into a
37 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
37 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
38 ls c
38 ls c
39
39
40 netstat -tnap 2>/dev/null | grep $HGPORT | grep LISTEN
40 hg --cwd a serve -a localhost -p $HGPORT -d --pid-file=hg.pid
41 hg --cwd a serve -a localhost -p $HGPORT -d --pid-file=hg.pid
41 cat a/hg.pid >> "$DAEMON_PIDS"
42 cat a/hg.pid >> "$DAEMON_PIDS"
42
43
43 echo '% fetch over http, no auth'
44 echo '% fetch over http, no auth'
44 hg --cwd d fetch -d '5 0' http://localhost:$HGPORT/ | hideport | hidehash
45 hg --cwd d fetch -d '5 0' http://localhost:$HGPORT/ | hideport | hidehash
45 hg --cwd d tip --template '{desc}\n' | hideport
46 hg --cwd d tip --template '{desc}\n' | hideport
46
47
47 echo '% fetch over http with auth (should be hidden in desc)'
48 echo '% fetch over http with auth (should be hidden in desc)'
48 hg --cwd e fetch -d '5 0' http://user:password@localhost:$HGPORT/ | hideport | hidehash
49 hg --cwd e fetch -d '5 0' http://user:password@localhost:$HGPORT/ | hideport | hidehash
49 hg --cwd e tip --template '{desc}\n' | hideport
50 hg --cwd e tip --template '{desc}\n' | hideport
50
51
51 hg clone a f
52 hg clone a f
52 hg clone a g
53 hg clone a g
53
54
54 echo f > f/f
55 echo f > f/f
55 hg --cwd f ci -d '6 0' -Amf
56 hg --cwd f ci -d '6 0' -Amf
56
57
57 echo g > g/g
58 echo g > g/g
58 hg --cwd g ci -d '6 0' -Amg
59 hg --cwd g ci -d '6 0' -Amg
59
60
60 hg clone -q f h
61 hg clone -q f h
61 hg clone -q g i
62 hg clone -q g i
62
63
63 echo % should merge f into g
64 echo % should merge f into g
64 hg --cwd g fetch -d '7 0' --switch -m 'automated merge' ../f
65 hg --cwd g fetch -d '7 0' --switch -m 'automated merge' ../f
65
66
66 rm i/g
67 rm i/g
67 echo % should abort, because i is modified
68 echo % should abort, because i is modified
68 hg --cwd i fetch ../h
69 hg --cwd i fetch ../h
69
70
70
71
71 echo % test fetch with named branches
72 echo % test fetch with named branches
72 hg init nbase
73 hg init nbase
73 echo base > nbase/a
74 echo base > nbase/a
74 hg -R nbase ci -d '1 0' -Am base
75 hg -R nbase ci -d '1 0' -Am base
75 hg -R nbase branch a
76 hg -R nbase branch a
76 echo a > nbase/a
77 echo a > nbase/a
77 hg -R nbase ci -d '2 0' -m a
78 hg -R nbase ci -d '2 0' -m a
78 hg -R nbase up -C 0
79 hg -R nbase up -C 0
79 hg -R nbase branch b
80 hg -R nbase branch b
80 echo b > nbase/b
81 echo b > nbase/b
81 hg -R nbase ci -Ad '3 0' -m b
82 hg -R nbase ci -Ad '3 0' -m b
82
83
83 echo
84 echo
84 echo % pull in change on foreign branch
85 echo % pull in change on foreign branch
85 hg clone nbase n1
86 hg clone nbase n1
86 hg clone nbase n2
87 hg clone nbase n2
87 hg -R n1 up -C a
88 hg -R n1 up -C a
88 echo aa > n1/a
89 echo aa > n1/a
89 hg -R n1 ci -d '4 0' -m a1
90 hg -R n1 ci -d '4 0' -m a1
90
91
91 hg -R n2 up -C b
92 hg -R n2 up -C b
92 hg -R n2 fetch -d '9 0' -m 'merge' n1
93 hg -R n2 fetch -d '9 0' -m 'merge' n1
93 echo '% parent should be 2 (no automatic update)'
94 echo '% parent should be 2 (no automatic update)'
94 hg -R n2 parents --template '{rev}\n'
95 hg -R n2 parents --template '{rev}\n'
95 rm -fr n1 n2
96 rm -fr n1 n2
96
97
97 echo
98 echo
98 echo % pull in changes on both foreign and local branches
99 echo % pull in changes on both foreign and local branches
99 hg clone nbase n1
100 hg clone nbase n1
100 hg clone nbase n2
101 hg clone nbase n2
101 hg -R n1 up -C a
102 hg -R n1 up -C a
102 echo aa > n1/a
103 echo aa > n1/a
103 hg -R n1 ci -d '4 0' -m a1
104 hg -R n1 ci -d '4 0' -m a1
104 hg -R n1 up -C b
105 hg -R n1 up -C b
105 echo bb > n1/b
106 echo bb > n1/b
106 hg -R n1 ci -d '5 0' -m b1
107 hg -R n1 ci -d '5 0' -m b1
107
108
108 hg -R n2 up -C b
109 hg -R n2 up -C b
109 hg -R n2 fetch -d '9 0' -m 'merge' n1
110 hg -R n2 fetch -d '9 0' -m 'merge' n1
110 echo '% parent should be 4 (fast forward)'
111 echo '% parent should be 4 (fast forward)'
111 hg -R n2 parents --template '{rev}\n'
112 hg -R n2 parents --template '{rev}\n'
112 rm -fr n1 n2
113 rm -fr n1 n2
113
114
114 echo
115 echo
115 echo '% pull changes on foreign (2 new heads) and local (1 new head) branches'
116 echo '% pull changes on foreign (2 new heads) and local (1 new head) branches'
116 echo % with a local change
117 echo % with a local change
117 hg clone nbase n1
118 hg clone nbase n1
118 hg clone nbase n2
119 hg clone nbase n2
119 hg -R n1 up -C a
120 hg -R n1 up -C a
120 echo a1 > n1/a
121 echo a1 > n1/a
121 hg -R n1 ci -d '4 0' -m a1
122 hg -R n1 ci -d '4 0' -m a1
122 hg -R n1 up -C b
123 hg -R n1 up -C b
123 echo bb > n1/b
124 echo bb > n1/b
124 hg -R n1 ci -d '5 0' -m b1
125 hg -R n1 ci -d '5 0' -m b1
125 hg -R n1 up -C 1
126 hg -R n1 up -C 1
126 echo a2 > n1/a
127 echo a2 > n1/a
127 hg -R n1 ci -d '6 0' -m a2
128 hg -R n1 ci -d '6 0' -m a2
128
129
129 hg -R n2 up -C b
130 hg -R n2 up -C b
130 echo change >> n2/c
131 echo change >> n2/c
131 hg -R n2 ci -Ad '7 0' -m local
132 hg -R n2 ci -Ad '7 0' -m local
132 hg -R n2 fetch -d '9 0' -m 'merge' n1
133 hg -R n2 fetch -d '9 0' -m 'merge' n1
133 echo '% parent should be 7 (new merge changeset)'
134 echo '% parent should be 7 (new merge changeset)'
134 hg -R n2 parents --template '{rev}\n'
135 hg -R n2 parents --template '{rev}\n'
135 rm -fr n1 n2
136 rm -fr n1 n2
136
137
137 echo '% pull in changes on foreign (merge of local branch) and local (2 new'
138 echo '% pull in changes on foreign (merge of local branch) and local (2 new'
138 echo '% heads) with a local change'
139 echo '% heads) with a local change'
139 hg clone nbase n1
140 hg clone nbase n1
140 hg clone nbase n2
141 hg clone nbase n2
141 hg -R n1 up -C a
142 hg -R n1 up -C a
142 hg -R n1 merge b
143 hg -R n1 merge b
143 hg -R n1 ci -d '4 0' -m merge
144 hg -R n1 ci -d '4 0' -m merge
144 hg -R n1 up -C 2
145 hg -R n1 up -C 2
145 echo c > n1/a
146 echo c > n1/a
146 hg -R n1 ci -d '5 0' -m c
147 hg -R n1 ci -d '5 0' -m c
147 hg -R n1 up -C 2
148 hg -R n1 up -C 2
148 echo cc > n1/a
149 echo cc > n1/a
149 hg -R n1 ci -d '6 0' -m cc
150 hg -R n1 ci -d '6 0' -m cc
150
151
151 hg -R n2 up -C b
152 hg -R n2 up -C b
152 echo change >> n2/b
153 echo change >> n2/b
153 hg -R n2 ci -Ad '7 0' -m local
154 hg -R n2 ci -Ad '7 0' -m local
154 hg -R n2 fetch -d '9 0' -m 'merge' n1
155 hg -R n2 fetch -d '9 0' -m 'merge' n1
155 echo '% parent should be 3 (fetch did not merge anything)'
156 echo '% parent should be 3 (fetch did not merge anything)'
156 hg -R n2 parents --template '{rev}\n'
157 hg -R n2 parents --template '{rev}\n'
157 rm -fr n1 n2
158 rm -fr n1 n2
158
159
159 echo % pull in change on different branch than dirstate
160 echo % pull in change on different branch than dirstate
160 hg init n1
161 hg init n1
161 echo a > n1/a
162 echo a > n1/a
162 hg -R n1 ci -Am initial
163 hg -R n1 ci -Am initial
163 hg clone n1 n2
164 hg clone n1 n2
164 echo b > n1/a
165 echo b > n1/a
165 hg -R n1 ci -m next
166 hg -R n1 ci -m next
166 hg -R n2 branch topic
167 hg -R n2 branch topic
167 hg -R n2 fetch -d '0 0' -m merge n1
168 hg -R n2 fetch -d '0 0' -m merge n1
168 echo '% parent should be 0 (fetch did not update or merge anything)'
169 echo '% parent should be 0 (fetch did not update or merge anything)'
169 hg -R n2 parents --template '{rev}\n'
170 hg -R n2 parents --template '{rev}\n'
170 rm -fr n1 n2
171 rm -fr n1 n2
171
172
173 "$TESTDIR/killdaemons.py"
174
172 true
175 true
General Comments 0
You need to be logged in to leave comments. Login now