##// END OF EJS Templates
test: add some assert in the bookrace extension...
marmoute -
r42708:c4d1807b stable
parent child Browse files
Show More
@@ -1,240 +1,242 b''
1 1 ================================
2 2 Test corner case around bookmark
3 3 ================================
4 4
5 5 This test file is meant to gather test around bookmark that are specific
6 6 enough to not find a place elsewhere.
7 7
8 8 Test bookmark/changelog race condition
9 9 ======================================
10 10
11 11 The data from the bookmark file are filtered to only contains bookmark with
12 12 node known to the changelog. If the cache invalidation between these two bits
13 13 goes wrong, bookmark can be dropped.
14 14
15 15 global setup
16 16 ------------
17 17
18 18 $ cat >> $HGRCPATH << EOF
19 19 > [ui]
20 20 > ssh = "$PYTHON" "$TESTDIR/dummyssh"
21 21 > [server]
22 22 > concurrent-push-mode=check-related
23 23 > EOF
24 24
25 25 Setup
26 26 -----
27 27
28 28 initial repository setup
29 29
30 30 $ hg init bookrace-server
31 31 $ cd bookrace-server
32 32 $ echo a > a
33 33 $ hg add a
34 34 $ hg commit -m root
35 35 $ echo a >> a
36 36 $ hg bookmark book-A
37 37 $ hg commit -m A0
38 38 $ hg up 'desc(root)'
39 39 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
40 40 (leaving bookmark book-A)
41 41 $ echo b > b
42 42 $ hg add b
43 43 $ hg bookmark book-B
44 44 $ hg commit -m B0
45 45 created new head
46 46 $ hg up null
47 47 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
48 48 (leaving bookmark book-B)
49 49 $ hg phase --public --rev 'all()'
50 50 $ hg log -G
51 51 o changeset: 2:c79985706978
52 52 | bookmark: book-B
53 53 | tag: tip
54 54 | parent: 0:6569b5a81c7e
55 55 | user: test
56 56 | date: Thu Jan 01 00:00:00 1970 +0000
57 57 | summary: B0
58 58 |
59 59 | o changeset: 1:39c28d785860
60 60 |/ bookmark: book-A
61 61 | user: test
62 62 | date: Thu Jan 01 00:00:00 1970 +0000
63 63 | summary: A0
64 64 |
65 65 o changeset: 0:6569b5a81c7e
66 66 user: test
67 67 date: Thu Jan 01 00:00:00 1970 +0000
68 68 summary: root
69 69
70 70 $ hg book
71 71 book-A 1:39c28d785860
72 72 book-B 2:c79985706978
73 73 $ cd ..
74 74
75 75 Add new changeset on each bookmark in distinct clones
76 76
77 77 $ hg clone ssh://user@dummy/bookrace-server client-A
78 78 requesting all changes
79 79 adding changesets
80 80 adding manifests
81 81 adding file changes
82 82 added 3 changesets with 3 changes to 2 files (+1 heads)
83 83 new changesets 6569b5a81c7e:c79985706978
84 84 updating to branch default
85 85 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
86 86 $ hg -R client-A update book-A
87 87 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
88 88 (activating bookmark book-A)
89 89 $ echo a >> client-A/a
90 90 $ hg -R client-A commit -m A1
91 91 $ hg clone ssh://user@dummy/bookrace-server client-B
92 92 requesting all changes
93 93 adding changesets
94 94 adding manifests
95 95 adding file changes
96 96 added 3 changesets with 3 changes to 2 files (+1 heads)
97 97 new changesets 6569b5a81c7e:c79985706978
98 98 updating to branch default
99 99 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
100 100 $ hg -R client-B update book-B
101 101 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
102 102 (activating bookmark book-B)
103 103 $ echo b >> client-B/b
104 104 $ hg -R client-B commit -m B1
105 105
106 106 extension to reproduce the race
107 107 -------------------------------
108 108
109 109 If two process are pushing we want to make sure the following happens:
110 110
111 111 * process A read changelog
112 112 * process B to its full push
113 113 * process A read bookmarks
114 114 * process A proceed with rest of the push
115 115
116 116 We build a server side extension for this purpose
117 117
118 118 $ cat > bookrace.py << EOF
119 119 > import os
120 120 > import time
121 121 > import atexit
122 122 > from mercurial import error, extensions, bookmarks
123 123 >
124 > def wait():
124 > def wait(repo):
125 125 > if not os.path.exists('push-A-started'):
126 > assert repo._currentlock(repo._lockref) is None
127 > assert repo._currentlock(repo._wlockref) is None
126 128 > print('setting raced push up')
127 129 > with open('push-A-started', 'w'):
128 130 > pass
129 131 > clock = 300
130 132 > while not os.path.exists('push-B-done'):
131 133 > clock -= 1
132 134 > if clock <= 0:
133 135 > raise error.Abort("race scenario timed out")
134 136 > time.sleep(0.1)
135 137 >
136 138 > def wrapinit(orig, self, repo):
137 > wait()
139 > wait(repo)
138 140 > return orig(self, repo)
139 141 > def uisetup(ui):
140 142 > extensions.wrapfunction(bookmarks.bmstore, '__init__', wrapinit)
141 143 > def e():
142 144 > with open('push-A-done', 'w'):
143 145 > pass
144 146 > atexit.register(e)
145 147 > EOF
146 148
147 149 Actual test
148 150 -----------
149 151
150 152 Start the raced push.
151 153
152 154 $ cat >> bookrace-server/.hg/hgrc << EOF
153 155 > [extensions]
154 156 > bookrace=$TESTTMP/bookrace.py
155 157 > EOF
156 158 $ hg push -R client-A -r book-A >push-output.txt 2>&1 &
157 159
158 160 Wait up to 30 seconds for that push to start.
159 161
160 162 $ clock=30
161 163 $ while [ ! -f push-A-started ] && [ $clock -gt 0 ] ; do
162 164 > clock=`expr $clock - 1`
163 165 > sleep 1
164 166 > done
165 167
166 168 Do the other push.
167 169
168 170 $ cat >> bookrace-server/.hg/hgrc << EOF
169 171 > [extensions]
170 172 > bookrace=!
171 173 > EOF
172 174
173 175 $ hg push -R client-B -r book-B
174 176 pushing to ssh://user@dummy/bookrace-server
175 177 searching for changes
176 178 remote: adding changesets
177 179 remote: adding manifests
178 180 remote: adding file changes
179 181 remote: added 1 changesets with 1 changes to 1 files
180 182 updating bookmark book-B
181 183
182 184 Signal the raced put that we are done (it waits up to 30 seconds).
183 185
184 186 $ touch push-B-done
185 187
186 188 Wait for the raced push to finish (with the remaning of the initial 30 seconds).
187 189
188 190 $ while [ ! -f push-A-done ] && [ $clock -gt 0 ] ; do
189 191 > clock=`expr $clock - 1`
190 192 > sleep 1
191 193 > done
192 194
193 195 Check raced push output.
194 196
195 197 $ cat push-output.txt
196 198 pushing to ssh://user@dummy/bookrace-server
197 199 searching for changes
198 200 remote: setting raced push up
199 201 remote: adding changesets
200 202 remote: adding manifests
201 203 remote: adding file changes
202 204 remote: added 1 changesets with 1 changes to 1 files
203 205 updating bookmark book-A
204 206
205 207 Check result of the push.
206 208
207 209 $ hg -R bookrace-server log -G
208 210 o changeset: 4:9ce3b28c16de
209 211 | bookmark: book-A
210 212 | tag: tip
211 213 | parent: 1:39c28d785860
212 214 | user: test
213 215 | date: Thu Jan 01 00:00:00 1970 +0000
214 216 | summary: A1
215 217 |
216 218 | o changeset: 3:f26c3b5167d1
217 219 | | bookmark: book-B
218 220 | | user: test
219 221 | | date: Thu Jan 01 00:00:00 1970 +0000
220 222 | | summary: B1
221 223 | |
222 224 | o changeset: 2:c79985706978
223 225 | | parent: 0:6569b5a81c7e
224 226 | | user: test
225 227 | | date: Thu Jan 01 00:00:00 1970 +0000
226 228 | | summary: B0
227 229 | |
228 230 o | changeset: 1:39c28d785860
229 231 |/ user: test
230 232 | date: Thu Jan 01 00:00:00 1970 +0000
231 233 | summary: A0
232 234 |
233 235 o changeset: 0:6569b5a81c7e
234 236 user: test
235 237 date: Thu Jan 01 00:00:00 1970 +0000
236 238 summary: root
237 239
238 240 $ hg -R bookrace-server book
239 241 book-A 4:9ce3b28c16de
240 242 book-B 3:f26c3b5167d1
General Comments 0
You need to be logged in to leave comments. Login now