tests/test-transaction-rollback-on-sigpipe.t
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 18 Jan 2022 13:05:21 -0800
changeset 49060 f3aafd785e65
parent 47951 9c4204b7f3e4
permissions -rw-r--r--
filemerge: add support for partial conflict resolution by external tool A common class of merge conflicts is in imports/#includes/etc. It's relatively easy to write a tool that can resolve these conflicts, perhaps by naively just unioning the statements and leaving any cleanup to other tools to do later [1]. Such specialized tools cannot generally resolve all conflicts in a file, of course. Let's therefore call them "partial merge tools". Note that the internal simplemerge algorithm is such a partial merge tool - one that only resolves trivial "conflicts" where one side is unchanged or both sides change in the same way. One can also imagine having smarter language-aware partial tools that merge the AST. It may be useful for such tools to interactively let the user resolve any conflicts it can't resolve itself. However, having the option of implementing it as a partial merge tool means that the developer doesn't *need* to create a UI for it. Instead, the user can resolve any remaining conflicts with their regular merge tool (e.g. `:merge3` or `meld). We don't currently have a way to let the user define such partial merge tools. That's what this patch addresses. It lets the user configure partial merge tools to run. Each tool can be configured to run only on files matching certain patterns (e.g. "*.py"). The tool takes three inputs (local, base, other) and resolves conflicts by updating these in place. For example, let's say the inputs are these: base: ``` import sys def main(): print('Hello') ``` local: ``` import os import sys def main(): print('Hi') ``` other: ``` import re import sys def main(): print('Howdy') ``` A partial merge tool could now resolve the conflicting imports by replacing the import statements in *all* files by the following snippet, while leaving the remainder of the files unchanged. ``` import os import re import sys ``` As a result, simplemerge and any regular merge tool that runs after the partial merge tool(s) will consider the imports to be non-conflicting and will only present the conflict in `main()` to the user. Differential Revision: https://phab.mercurial-scm.org/D12356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47317
aa07bcc4f505 test: remove some unnecessary dependency on repo format
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47312
diff changeset
     1
Test that, when an hg push is interrupted and the remote side receives SIGPIPE,
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
     2
the remote hg is able to successfully roll back the transaction.
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
     3
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
     4
  $ hg init -q remote
47951
9c4204b7f3e4 tests: rely on dummyssh being the default
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47618
diff changeset
     5
  $ hg clone -q ssh://user@dummy/`pwd`/remote local
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
     6
  $ SIGPIPE_REMOTE_DEBUG_FILE="$TESTTMP/DEBUGFILE"
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
     7
  $ SYNCFILE1="$TESTTMP/SYNCFILE1"
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
     8
  $ SYNCFILE2="$TESTTMP/SYNCFILE2"
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
     9
  $ export SIGPIPE_REMOTE_DEBUG_FILE
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    10
  $ export SYNCFILE1
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    11
  $ export SYNCFILE2
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    12
  $ PYTHONUNBUFFERED=1
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    13
  $ export PYTHONUNBUFFERED
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    14
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    15
On the remote end, run hg, piping stdout and stderr through processes that we
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    16
know the PIDs of. We will later kill these to simulate an ssh client
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    17
disconnecting.
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    18
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    19
  $ remotecmd="$RUNTESTDIR/testlib/sigpipe-remote.py"
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    20
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    21
In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    22
disconnecting. Then exit nonzero, to force a transaction rollback.
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    23
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    24
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    25
  $ cat >remote/.hg/hgrc <<EOF
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    26
  > [hooks]
47615
a8d1adeeba87 test-sigpipe: run the hook using `sh`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47588
diff changeset
    27
  > pretxnchangegroup.00-break-things=sh "$RUNTESTDIR/testlib/wait-on-file" 10 "$SYNCFILE2" "$SYNCFILE1"
47556
640fdb7fd67b test: make sure we hit the SIGPIPE in test-transaction-rollback-on-sigpipe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47555
diff changeset
    28
  > pretxnchangegroup.01-output-things=echo "some remote output to be forward to the closed pipe"
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    29
  > pretxnchangegroup.02-output-things=echo "some more remote output"
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    30
  > EOF
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    31
47555
452795b0b69a test: clarify some output in `test-transaction-rollback-on-sigpipe`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47317
diff changeset
    32
  $ hg --cwd ./remote tip -T '{node|short}\n'
452795b0b69a test: clarify some output in `test-transaction-rollback-on-sigpipe`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47317
diff changeset
    33
  000000000000
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    34
  $ cd local
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    35
  $ echo foo > foo ; hg commit -qAm "commit"
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    36
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    37
(use quiet to avoid flacky output from the server)
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    38
47951
9c4204b7f3e4 tests: rely on dummyssh being the default
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47618
diff changeset
    39
  $ hg push --quiet --remotecmd "$remotecmd"
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    40
  abort: stream ended unexpectedly (got 0 bytes, expected 4)
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    41
  [255]
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    42
  $ cat $SIGPIPE_REMOTE_DEBUG_FILE
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    43
  SIGPIPE-HELPER: Starting
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    44
  SIGPIPE-HELPER: Redirection in place
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    45
  SIGPIPE-HELPER: pipes closed in main
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    46
  SIGPIPE-HELPER: SYNCFILE1 detected
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    47
  SIGPIPE-HELPER: worker killed
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    48
  SIGPIPE-HELPER: creating SYNCFILE2
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    49
  SIGPIPE-HELPER: Shutting down
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    50
  SIGPIPE-HELPER: Server process terminated with status 255 (no-windows !)
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    51
  SIGPIPE-HELPER: Server process terminated with status 1 (windows !)
47557
ed81f2be5527 test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47556
diff changeset
    52
  SIGPIPE-HELPER: Shut down
45736
2c6b054e22d0 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff changeset
    53
47317
aa07bcc4f505 test: remove some unnecessary dependency on repo format
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47312
diff changeset
    54
The remote should be left in a good state
47555
452795b0b69a test: clarify some output in `test-transaction-rollback-on-sigpipe`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47317
diff changeset
    55
  $ hg --cwd ../remote tip -T '{node|short}\n'
452795b0b69a test: clarify some output in `test-transaction-rollback-on-sigpipe`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47317
diff changeset
    56
  000000000000
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    57
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    58
#if windows
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    59
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    60
XXX-Windows Broken behavior to be fixed
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    61
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    62
Behavior on Windows is broken and should be fixed. However this is a fairly
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    63
corner case situation and no data are being corrupted. This would affect
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    64
central repository being hosted on a Windows machine and accessed using ssh.
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    65
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    66
This was catch as we setup new CI for Windows. Making the test pass on Windows
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    67
was enough of a pain that fixing the behavior set aside for now. Dear and
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    68
honorable reader, feel free to fix it.
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    69
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    70
  $ hg --cwd ../remote recover
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    71
  rolling back interrupted transaction
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    72
  (verify step skipped, run `hg verify` to check your repository content)
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    73
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    74
#else
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    75
47317
aa07bcc4f505 test: remove some unnecessary dependency on repo format
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47312
diff changeset
    76
  $ hg --cwd ../remote recover
aa07bcc4f505 test: remove some unnecessary dependency on repo format
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 47312
diff changeset
    77
  no interrupted transaction available
45737
b3e8d8e4a40d hook: ignore EPIPE when flushing stdout/stderr
Mitchell Plamann <mplamann@janestreet.com>
parents: 45736
diff changeset
    78
  [1]
47618
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    79
27ff81547d35 sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47615
diff changeset
    80
#endif