tests/test-racy-mutations.t
author Cédric Krier <ced@b2ck.com>
Thu, 26 Jan 2023 00:23:07 +0100
changeset 49956 2282d8ac0fa9
parent 49047 c827bb7b5806
child 49991 3997c64eff8b
permissions -rw-r--r--
filemerge: add union-other-first as internal merge tool See inline documentation for details.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     1
#testcases skip-detection fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     3
Test situations that "should" only be reproducible:
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     4
- on networked filesystems, or
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     5
- user using `hg debuglocks` to eliminate the lock file, or
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     6
- something (that doesn't respect the lock file) writing to the .hg directory
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     7
while we're running
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     8
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     9
  $ hg init a
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    10
  $ cd a
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    11
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    12
  $ cat > "$TESTTMP_FORWARD_SLASH/waitlock_editor.sh" <<EOF
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    13
  >     [ -n "\${WAITLOCK_ANNOUNCE:-}" ] && touch "\${WAITLOCK_ANNOUNCE}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    14
  >     f="\${WAITLOCK_FILE}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    15
  >     start=\`date +%s\`
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    16
  >     timeout=5
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    17
  >     "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" "\$timeout" "\$f"
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    18
  >     if [ \$# -gt 1 ]; then
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    19
  >         cat "\$@"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    20
  >     fi
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    21
  > EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    22
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    23
Things behave differently if we don't already have a 00changelog.i file when
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    24
this all starts, so let's make one.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    25
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    26
  $ echo r0 > r0
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    27
  $ hg commit -qAm 'r0'
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    28
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    29
Start an hg commit that will take a while
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    30
  $ EDITOR_STARTED="$TESTTMP_FORWARD_SLASH/a/.editor_started"
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    31
  $ MISCHIEF_MANAGED="$TESTTMP_FORWARD_SLASH/a/.mischief_managed"
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    32
  $ JOBS_FINISHED="$TESTTMP_FORWARD_SLASH/a/.jobs_finished"
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    33
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    34
#if fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    35
  $ cat >> .hg/hgrc << EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    36
  > [debug]
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    37
  > revlog.verifyposition.changelog = fail
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    38
  > EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    39
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    40
49046
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    41
  $ cat >> .hg/hgrc << EOF
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    42
  > [ui]
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    43
  > editor=sh $TESTTMP_FORWARD_SLASH/waitlock_editor.sh
49046
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    44
  > EOF
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    45
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    46
  $ echo foo > foo
49046
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    47
  $ (unset HGEDITOR;
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    48
  >      WAITLOCK_ANNOUNCE="${EDITOR_STARTED}" \
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    49
  >      WAITLOCK_FILE="${MISCHIEF_MANAGED}" \
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    50
  >           hg commit -qAm 'r1 (foo)' --edit foo > .foo_commit_out 2>&1 ; touch "${JOBS_FINISHED}") &
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    51
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    52
Wait for the "editor" to actually start
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    53
  $ sh "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" 5 "${EDITOR_STARTED}"
49046
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    54
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    55
  $ cat >> .hg/hgrc << EOF
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    56
  > [ui]
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    57
  > editor=
dd384ad01d88 tests-racy-mutation: pass the editor through config instead of env variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48977
diff changeset
    58
  > EOF
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    59
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    60
Break the locks, and make another commit.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    61
  $ hg debuglocks -LW
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    62
  $ echo bar > bar
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    63
  $ hg commit -qAm 'r2 (bar)' bar
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    64
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    65
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    66
       0       0 222799e2f90b 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    67
       1       1 6f124f6007a0 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    68
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    69
Awaken the editor from that first commit
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    70
  $ touch "${MISCHIEF_MANAGED}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    71
And wait for it to finish
49047
c827bb7b5806 run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49046
diff changeset
    72
  $ WAITLOCK_FILE="${JOBS_FINISHED}" sh "$TESTTMP_FORWARD_SLASH/waitlock_editor.sh"
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    73
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    74
#if skip-detection
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    75
(Ensure there was no output)
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    76
  $ cat .foo_commit_out
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    77
And observe a corrupted repository -- rev 2's linkrev is 1, which should never
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    78
happen for the changelog (the linkrev should always refer to itself).
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    79
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    80
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    81
       0       0 222799e2f90b 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    82
       1       1 6f124f6007a0 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    83
       2       1 ac80e6205bb2 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    84
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    85
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    86
#if fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    87
  $ cat .foo_commit_out
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    88
  transaction abort!
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    89
  rollback completed
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    90
  note: commit message saved in .hg/last-message.txt
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    91
  note: use 'hg commit --logfile .hg/last-message.txt --edit' to reuse it
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    92
  abort: 00changelog.i: file cursor at position 249, expected 121
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    93
And no corruption in the changelog.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    94
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    95
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    96
       0       0 222799e2f90b 000000000000 000000000000
47214
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47065
diff changeset
    97
       1       1 6f124f6007a0 222799e2f90b 000000000000 (missing-correct-output !)
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    98
And, because of transactions, there's none in the manifestlog either.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    99
  $ hg debugrevlogindex -m
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
   100
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
   101
       0       0 7b7020262a56 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
   102
       1       1 ad3fe36d86d9 7b7020262a56 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
   103
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
   104