tests/test-chg.t
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 26 Mar 2018 11:00:16 -0700
changeset 37288 9bfcbe4f4745
parent 34316 b94db1780365
child 39723 5abc47d4ca6b
permissions -rw-r--r--
wireproto: add streams to frame-based protocol Previously, the frame-based protocol was just a series of frames, with each frame associated with a request ID. In order to scale the protocol, we'll want to enable the use of compression. While it is possible to enable compression at the socket/pipe level, this has its disadvantages. The big one is it undermines the point of frames being standalone, atomic units that can be read and written: if you add compression above the framing protocol, you are back to having a stream-based protocol as opposed to something frame-based. So in order to preserve frames, compression needs to occur at the frame payload level. Compressing each frame's payload individually will limit compression ratios because the window size of the compressor will be limited by the max frame size, which is 32-64kb as currently defined. It will also add CPU overhead, as it is more efficient for compressors to operate on fewer, larger blocks of data than more, smaller blocks. So compressing each frame independently is out. This means we need to compress each frame's payload as if it is part of a larger stream. The simplest approach is to have 1 stream per connection. This could certainly work. However, it has disadvantages (documented below). We could also have 1 stream per RPC/command invocation. (This is the model HTTP/2 goes with.) This also has disadvantages. The main disadvantage to one global stream is that it has the very real potential to create CPU bottlenecks doing compression. Networks are only getting faster and the performance of single CPU cores has been relatively flat. Newer compression formats like zstandard offer better CPU cycle efficiency than predecessors like zlib. But it still all too common to saturate your CPU with compression overhead long before you saturate the network pipe. The main disadvantage with streams per request is that you can't reap the benefits of the compression context for multiple requests. For example, if you send 1000 RPC requests (or HTTP/2 requests for that matter), the response to each would have its own compression context. The overall size of the raw responses would be larger because compression contexts wouldn't be able to reference data from another request or response. The approach for streams as implemented in this commit is to support N streams per connection and for streams to potentially span requests and responses. As explained by the added internals docs, this facilitates servers and clients delegating independent streams and compression to independent threads / CPU cores. This helps alleviate the CPU bottleneck of compression. This design also allows compression contexts to be reused across requests/responses. This can result in improved compression ratios and less overhead for compressors and decompressors having to build new contexts. Another feature that was defined was the ability for individual frames within a stream to declare whether that individual frame's payload uses the content encoding (read: compression) defined by the stream. The idea here is that some servers may serve data from a combination of caches and dynamic resolution. Data coming from caches may be pre-compressed. We want to facilitate servers being able to essentially stream bytes from caches to the wire with minimal overhead. Being able to mix and match with frames are compressed within a stream enables these types of advanced server functionality. This commit defines the new streams mechanism. Basic code for supporting streams in frames has been added. But that code is seriously lacking and doesn't fully conform to the defined protocol. For example, we don't close any streams. And support for content encoding within streams is not yet implemented. The change was rather invasive and I didn't think it would be reasonable to implement the entire feature in a single commit. For the record, I would have loved to reuse an existing multiplexing protocol to build the new wire protocol on top of. However, I couldn't find a protocol that offers the performance and scaling characteristics that I desired. Namely, it should support multiple compression contexts to facilitate scaling out to multiple CPU cores and compression contexts should be able to live longer than single RPC requests. HTTP/2 *almost* fits the bill. But the semantics of HTTP message exchange state that streams can only live for a single request-response. We /could/ tunnel on top of HTTP/2 streams and frames with HEADER and DATA frames. But there's no guarantee that HTTP/2 libraries and proxies would allow us to use HTTP/2 streams and frames without the HTTP message exchange semantics defined in RFC 7540 Section 8. Other RPC protocols like gRPC tunnel are built on top of HTTP/2 and thus preserve its semantics of stream per RPC invocation. Even QUIC does this. We could attempt to invent a higher-level stream that spans HTTP/2 streams. But this would be violating HTTP/2 because there is no guarantee that HTTP/2 streams are routed to the same server. The best we can do - which is what this protocol does - is shoehorn all request and response data into a single HTTP message and create streams within. At that point, we've defined a Content-Type in HTTP parlance. It just so happens our media type can also work as a standalone, stream-based protocol, without leaning on HTTP or similar protocol. Differential Revision: https://phab.mercurial-scm.org/D2907
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29274
148a9a5379f0 test-chg: run only with chg
Yuya Nishihara <yuya@tcha.org>
parents: 29088
diff changeset
     1
#require chg
148a9a5379f0 test-chg: run only with chg
Yuya Nishihara <yuya@tcha.org>
parents: 29088
diff changeset
     2
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
     3
  $ cp $HGRCPATH $HGRCPATH.orig
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
     4
28516
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
init repo
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
29274
148a9a5379f0 test-chg: run only with chg
Yuya Nishihara <yuya@tcha.org>
parents: 29088
diff changeset
     7
  $ chg init foo
28516
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
  $ cd foo
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
ill-formed config
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
29274
148a9a5379f0 test-chg: run only with chg
Yuya Nishihara <yuya@tcha.org>
parents: 29088
diff changeset
    12
  $ chg status
28516
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
  $ echo '=brokenconfig' >> $HGRCPATH
29274
148a9a5379f0 test-chg: run only with chg
Yuya Nishihara <yuya@tcha.org>
parents: 29088
diff changeset
    14
  $ chg status
28516
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
    15
  hg: parse error at * (glob)
3bf2892f685f chgserver: handle ParseError during validate
Jun Wu <quark@fb.com>
parents:
diff changeset
    16
  [255]
29088
983353035cec chgserver: remove _clearenvaliases
Jun Wu <quark@fb.com>
parents: 28516
diff changeset
    17
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
    18
  $ cp $HGRCPATH.orig $HGRCPATH
30680
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    19
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    20
long socket path
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    21
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    22
  $ sockpath=$TESTTMP/this/path/should/be/longer/than/one-hundred-and-seven/characters/where/107/is/the/typical/size/limit/of/unix-domain-socket
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    23
  $ mkdir -p $sockpath
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    24
  $ bakchgsockname=$CHGSOCKNAME
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    25
  $ CHGSOCKNAME=$sockpath/server
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    26
  $ export CHGSOCKNAME
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    27
  $ chg root
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    28
  $TESTTMP/foo
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    29
  $ rm -rf $sockpath
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    30
  $ CHGSOCKNAME=$bakchgsockname
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    31
  $ export CHGSOCKNAME
c80c16a8a0b0 chg: support long socket path
Jun Wu <quark@fb.com>
parents: 30625
diff changeset
    32
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
    33
  $ cd ..
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
    34
31124
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    35
editor
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    36
------
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    37
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    38
  $ cat >> pushbuffer.py <<EOF
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    39
  > def reposetup(ui, repo):
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    40
  >     repo.ui.pushbuffer(subproc=True)
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    41
  > EOF
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    42
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    43
  $ chg init editor
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    44
  $ cd editor
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    45
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    46
by default, system() should be redirected to the client:
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    47
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    48
  $ touch foo
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    49
  $ CHGDEBUG= HGEDITOR=cat chg ci -Am channeled --edit 2>&1 \
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    50
  > | egrep "HG:|run 'cat"
34316
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
    51
  chg: debug: * run 'cat "*"' at '$TESTTMP/editor' (glob)
31124
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    52
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    53
  HG: Leave message empty to abort commit.
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    54
  HG: --
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    55
  HG: user: test
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    56
  HG: branch 'default'
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    57
  HG: added foo
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    58
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    59
but no redirection should be made if output is captured:
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    60
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    61
  $ touch bar
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    62
  $ CHGDEBUG= HGEDITOR=cat chg ci -Am bufferred --edit \
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    63
  > --config extensions.pushbuffer="$TESTTMP/pushbuffer.py" 2>&1 \
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    64
  > | egrep "HG:|run 'cat"
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    65
  [1]
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    66
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    67
check that commit commands succeeded:
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    68
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    69
  $ hg log -T '{rev}:{desc}\n'
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    70
  1:bufferred
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    71
  0:channeled
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    72
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    73
  $ cd ..
fbce78c58f1e chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents: 30847
diff changeset
    74
30847
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    75
pager
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    76
-----
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    77
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    78
  $ cat >> fakepager.py <<EOF
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    79
  > import sys
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    80
  > for line in sys.stdin:
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    81
  >     sys.stdout.write('paged! %r\n' % line)
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    82
  > EOF
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    83
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    84
enable pager extension globally, but spawns the master server with no tty:
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    85
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    86
  $ chg init pager
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    87
  $ cd pager
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    88
  $ cat >> $HGRCPATH <<EOF
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    89
  > [extensions]
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    90
  > pager =
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    91
  > [pager]
32958
75be14993fda cleanup: use $PYTHON to run python in many more tests
Augie Fackler <augie@google.com>
parents: 32376
diff changeset
    92
  > pager = $PYTHON $TESTTMP/fakepager.py
30847
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    93
  > EOF
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    94
  $ chg version > /dev/null
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    95
  $ touch foo
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    96
  $ chg ci -qAm foo
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    97
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    98
pager should be enabled if the attached client has a tty:
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
    99
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   100
  $ chg log -l1 -q --config ui.formatted=True
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   101
  paged! '0:1f7b0de80e11\n'
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   102
  $ chg log -l1 -q --config ui.formatted=False
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   103
  0:1f7b0de80e11
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   104
31890
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   105
chg waits for pager if runcommand raises
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   106
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   107
  $ cat > $TESTTMP/crash.py <<EOF
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31890
diff changeset
   108
  > from mercurial import registrar
31890
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   109
  > cmdtable = {}
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31890
diff changeset
   110
  > command = registrar.command(cmdtable)
33109
fce4ed2912bb py3: make sure commands name are bytes in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32958
diff changeset
   111
  > @command(b'crash')
31890
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   112
  > def pagercrash(ui, repo, *pats, **opts):
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   113
  >     ui.write('going to crash\n')
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   114
  >     raise Exception('.')
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   115
  > EOF
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   116
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   117
  $ cat > $TESTTMP/fakepager.py <<EOF
33967
0d0cec9602c3 tests: update test-chg to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 33109
diff changeset
   118
  > from __future__ import absolute_import
0d0cec9602c3 tests: update test-chg to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 33109
diff changeset
   119
  > import sys
0d0cec9602c3 tests: update test-chg to pass our import checker
Augie Fackler <raf@durin42.com>
parents: 33109
diff changeset
   120
  > import time
31890
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   121
  > for line in iter(sys.stdin.readline, ''):
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   122
  >     if 'crash' in line: # only interested in lines containing 'crash'
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   123
  >         # if chg exits when pager is sleeping (incorrectly), the output
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   124
  >         # will be captured by the next test case
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   125
  >         time.sleep(1)
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   126
  >         sys.stdout.write('crash-pager: %s' % line)
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   127
  > EOF
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   128
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   129
  $ cat >> .hg/hgrc <<EOF
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   130
  > [extensions]
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   131
  > crash = $TESTTMP/crash.py
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   132
  > EOF
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   133
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   134
  $ chg crash --pager=on --config ui.formatted=True 2>/dev/null
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   135
  crash-pager: going to crash
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   136
  [255]
ca7af5d15b21 chg: always wait for pager
Jun Wu <quark@fb.com>
parents: 31124
diff changeset
   137
30847
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   138
  $ cd ..
e12553cfd0a4 pager: wrap _runcommand() no matter if stdout is redirected
Yuya Nishihara <yuya@tcha.org>
parents: 30680
diff changeset
   139
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   140
server lifecycle
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   141
----------------
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   142
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   143
chg server should be restarted on code change, and old server will shut down
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   144
automatically. In this test, we use the following time parameters:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   145
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   146
 - "sleep 1" to make mtime different
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   147
 - "sleep 2" to notice mtime change (polling interval is 1 sec)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   148
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   149
set up repository with an extension:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   150
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   151
  $ chg init extreload
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   152
  $ cd extreload
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   153
  $ touch dummyext.py
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   154
  $ cat <<EOF >> .hg/hgrc
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   155
  > [extensions]
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   156
  > dummyext = dummyext.py
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   157
  > EOF
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   158
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   159
isolate socket directory for stable result:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   160
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   161
  $ OLDCHGSOCKNAME=$CHGSOCKNAME
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   162
  $ mkdir chgsock
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   163
  $ CHGSOCKNAME=`pwd`/chgsock/server
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   164
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   165
warm up server:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   166
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   167
  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
34316
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
   168
  chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   169
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   170
new server should be started if extension modified:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   171
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   172
  $ sleep 1
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   173
  $ touch dummyext.py
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   174
  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
34316
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
   175
  chg: debug: * instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
   176
  chg: debug: * instruction: reconnect (glob)
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
   177
  chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   178
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   179
old server will shut down, while new server should still be reachable:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   180
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   181
  $ sleep 2
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   182
  $ CHGDEBUG= chg log 2>&1 | (egrep 'instruction|start' || true)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   183
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   184
socket file should never be unlinked by old server:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   185
(simulates unowned socket by updating mtime, which makes sure server exits
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   186
at polling cycle)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   187
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   188
  $ ls chgsock/server-*
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   189
  chgsock/server-* (glob)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   190
  $ touch chgsock/server-*
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   191
  $ sleep 2
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   192
  $ ls chgsock/server-*
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   193
  chgsock/server-* (glob)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   194
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   195
since no server is reachable from socket file, new server should be started:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   196
(this test makes sure that old server shut down automatically)
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   197
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   198
  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
34316
b94db1780365 chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents: 33967
diff changeset
   199
  chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
29275
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   200
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   201
shut down servers and restore environment:
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   202
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   203
  $ rm -R chgsock
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   204
  $ CHGSOCKNAME=$OLDCHGSOCKNAME
e53f961ac75f test-chg: add basic tests for server lifecycle
Yuya Nishihara <yuya@tcha.org>
parents: 29274
diff changeset
   205
  $ cd ..