| 1 |
#testcases skip-detection fail-if-detected |
| 2 |
|
| 3 |
Test situations that "should" only be reproducible: |
| 4 |
- on networked filesystems, or |
| 5 |
- user using `hg debuglocks` to eliminate the lock file, or |
| 6 |
- something (that doesn't respect the lock file) writing to the .hg directory |
| 7 |
while we're running |
| 8 |
|
| 9 |
|
| 10 |
Initial setup |
| 11 |
------------- |
| 12 |
|
| 13 |
$ hg init base-repo |
| 14 |
$ cd base-repo |
| 15 |
|
| 16 |
$ cat > "$TESTTMP_FORWARD_SLASH/waitlock_editor.sh" <<EOF |
| 17 |
> [ -n "\${WAITLOCK_ANNOUNCE:-}" ] && touch "\${WAITLOCK_ANNOUNCE}" |
| 18 |
> f="\${WAITLOCK_FILE}" |
| 19 |
> start=\`date +%s\` |
| 20 |
> timeout=20 |
| 21 |
> "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" "\$timeout" "\$f" |
| 22 |
> if [ \$# -gt 1 ]; then |
| 23 |
> cat "\$@" |
| 24 |
> fi |
| 25 |
> EOF |
| 26 |
|
| 27 |
Things behave differently if we don't already have a 00changelog.i file when |
| 28 |
this all starts, so let's make one. |
| 29 |
|
| 30 |
$ echo r0 > r0 |
| 31 |
$ hg commit -qAm 'r0' |
| 32 |
|
| 33 |
$ cd .. |
| 34 |
$ cp -R base-repo main-client |
| 35 |
$ cp -R base-repo racing-client |
| 36 |
|
| 37 |
$ mkdir sync |
| 38 |
$ EDITOR_STARTED="$TESTTMP_FORWARD_SLASH/sync/.editor_started" |
| 39 |
$ MISCHIEF_MANAGED="$TESTTMP_FORWARD_SLASH/sync/.mischief_managed" |
| 40 |
$ JOBS_FINISHED="$TESTTMP_FORWARD_SLASH/sync/.jobs_finished" |
| 41 |
|
| 42 |
Actual test |
| 43 |
----------- |
| 44 |
|
| 45 |
Start an hg commit that will take a while |
| 46 |
|
| 47 |
$ cd main-client |
| 48 |
|
| 49 |
#if fail-if-detected |
| 50 |
$ cat >> $HGRCPATH << EOF |
| 51 |
> [debug] |
| 52 |
> revlog.verifyposition.changelog = fail |
| 53 |
> EOF |
| 54 |
#endif |
| 55 |
|
| 56 |
$ echo foo > foo |
| 57 |
$ ( |
| 58 |
> unset HGEDITOR; |
| 59 |
> WAITLOCK_ANNOUNCE="${EDITOR_STARTED}" \ |
| 60 |
> WAITLOCK_FILE="${MISCHIEF_MANAGED}" \ |
| 61 |
> hg commit -qAm 'r1 (foo)' --edit foo \ |
| 62 |
> --config ui.editor="sh $TESTTMP/waitlock_editor.sh" \ |
| 63 |
> > .foo_commit_out 2>&1 ;\ |
| 64 |
> touch "${JOBS_FINISHED}" |
| 65 |
> ) & |
| 66 |
|
| 67 |
Wait for the "editor" to actually start |
| 68 |
$ sh "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" 20 "${EDITOR_STARTED}" |
| 69 |
|
| 70 |
Do a concurrent edition |
| 71 |
$ cd ../racing-client |
| 72 |
$ touch ../pre-race |
| 73 |
$ sleep 10 |
| 74 |
$ echo bar > bar |
| 75 |
$ hg --repository ../racing-client commit -qAm 'r2 (bar)' bar |
| 76 |
$ hg --repository ../racing-client debugrevlogindex -c |
| 77 |
rev linkrev nodeid p1 p2 |
| 78 |
0 0 222799e2f90b 000000000000 000000000000 |
| 79 |
1 1 6f124f6007a0 222799e2f90b 000000000000 |
| 80 |
$ hg --repository ../racing-client debugrevlogindex -m |
| 81 |
rev linkrev nodeid p1 p2 |
| 82 |
0 0 7b7020262a56 000000000000 000000000000 |
| 83 |
1 1 ad3fe36d86d9 7b7020262a56 000000000000 |
| 84 |
|
| 85 |
|
| 86 |
We simulate an network FS race by overwriting raced repo content with the new |
| 87 |
content of the files changed in the racing repository |
| 88 |
|
| 89 |
$ for x in `find . -type f -newer ../pre-race`; do |
| 90 |
> cp $x ../main-client/$x |
| 91 |
> done |
| 92 |
$ cd ../main-client |
| 93 |
|
| 94 |
Awaken the editor from that first commit |
| 95 |
$ touch "${MISCHIEF_MANAGED}" |
| 96 |
And wait for it to finish |
| 97 |
$ WAITLOCK_FILE="${JOBS_FINISHED}" sh "$TESTTMP_FORWARD_SLASH/waitlock_editor.sh" |
| 98 |
|
| 99 |
#if skip-detection |
| 100 |
(Ensure there was no output) |
| 101 |
$ cat .foo_commit_out |
| 102 |
And observe a corrupted repository -- rev 2's linkrev is 1, which should never |
| 103 |
happen for the changelog (the linkrev should always refer to itself). |
| 104 |
$ hg debugrevlogindex -c |
| 105 |
rev linkrev nodeid p1 p2 |
| 106 |
0 0 222799e2f90b 000000000000 000000000000 |
| 107 |
1 1 6f124f6007a0 222799e2f90b 000000000000 |
| 108 |
2 1 ac80e6205bb2 222799e2f90b 000000000000 |
| 109 |
|
| 110 |
TODO: Figure out why the middle entry is missing on Windows. |
| 111 |
$ hg debugrevlogindex -m |
| 112 |
rev linkrev nodeid p1 p2 |
| 113 |
0 0 7b7020262a56 000000000000 000000000000 |
| 114 |
1 1 ad3fe36d86d9 7b7020262a56 000000000000 (no-windows !) |
| 115 |
2 1 d93163bb8ce3 7b7020262a56 000000000000 (no-windows !) |
| 116 |
1 1 d93163bb8ce3 7b7020262a56 000000000000 (windows !) |
| 117 |
|
| 118 |
#endif |
| 119 |
|
| 120 |
#if fail-if-detected |
| 121 |
$ cat .foo_commit_out |
| 122 |
note: commit message saved in .hg/last-message.txt |
| 123 |
note: use 'hg commit --logfile .hg/last-message.txt --edit' to reuse it |
| 124 |
transaction abort! |
| 125 |
rollback completed |
| 126 |
abort: 00changelog.i: file cursor at position 128, expected 64 |
| 127 |
And no corruption in the changelog. |
| 128 |
$ hg debugrevlogindex -c |
| 129 |
rev linkrev nodeid p1 p2 |
| 130 |
0 0 222799e2f90b 000000000000 000000000000 |
| 131 |
1 1 6f124f6007a0 222799e2f90b 000000000000 (missing-correct-output !) |
| 132 |
|
| 133 |
And, because of transactions, there's none in the manifestlog either. |
| 134 |
|
| 135 |
TODO: Figure out why this is different on Windows. |
| 136 |
$ hg debugrevlogindex -m |
| 137 |
rev linkrev nodeid p1 p2 |
| 138 |
0 0 7b7020262a56 000000000000 000000000000 |
| 139 |
1 1 ad3fe36d86d9 7b7020262a56 000000000000 (no-windows !) |
| 140 |
1 1 ad3fe36d86d9 7b7020262a56 000000000000 (missing-correct-output windows !) |
| 141 |
#endif |
| 142 |
|