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