tests/wireprotohelpers.sh
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 14 Apr 2018 15:19:36 -0700
changeset 37725 3ea8323d6f95
parent 37722 89a16704114c
child 37780 8acd3a9ac4fd
permissions -rw-r--r--
wireprotov2: change command response protocol to include a leading map The error handling mechanism for the new wire protocol isn't very well-defined. This commit takes us a step in the right direction by introducing a leading CBOR map for command responses. This map will contain an overall result of the command. Currently, the map indicates whether the command was overall successful or if an error occurred. And if an error occurred, that error is present in the map. There is still a dedicated error frame. My intent is to use that for protocol-level errors and for errors that are encountered after the initial response frame has been sent. This will be clarified in a later commit. Differential Revision: https://phab.mercurial-scm.org/D3385

HTTPV2=exp-http-v2-0001
MEDIATYPE=application/mercurial-exp-framing-0005

sendhttpraw() {
  hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
}

sendhttpv2peer() {
  hg --verbose debugwireproto --nologhandshake --peer http2 http://$LOCALIP:$HGPORT/
}

sendhttpv2peerhandshake() {
  hg --verbose debugwireproto --peer http2 http://$LOCALIP:$HGPORT/
}

cat > dummycommands.py << EOF
from mercurial import (
    wireprototypes,
    wireproto,
)

@wireproto.wireprotocommand('customreadonly', permission='pull')
def customreadonlyv1(repo, proto):
    return wireprototypes.bytesresponse(b'customreadonly bytes response')

@wireproto.wireprotocommand('customreadonly', permission='pull',
                            transportpolicy=wireproto.POLICY_V2_ONLY)
def customreadonlyv2(repo, proto):
    return wireprototypes.cborresponse(b'customreadonly bytes response')

@wireproto.wireprotocommand('customreadwrite', permission='push')
def customreadwrite(repo, proto):
    return wireprototypes.bytesresponse(b'customreadwrite bytes response')

@wireproto.wireprotocommand('customreadwrite', permission='push',
                            transportpolicy=wireproto.POLICY_V2_ONLY)
def customreadwritev2(repo, proto):
    return wireprototypes.cborresponse(b'customreadwrite bytes response')
EOF

cat >> $HGRCPATH << EOF
[extensions]
drawdag = $TESTDIR/drawdag.py
EOF

enabledummycommands() {
  cat >> $HGRCPATH << EOF
[extensions]
dummycommands = $TESTTMP/dummycommands.py
EOF
}

enablehttpv2() {
  cat >> $1/.hg/hgrc << EOF
[experimental]
web.apiserver = true
web.api.http-v2 = true
EOF
}