tests/test-bundle2-pushback.t
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 12 Feb 2018 16:35:06 -0800
changeset 36217 1ee1a42bfdae
parent 33947 0124cf4af3b7
child 38470 4c358bdaada8
permissions -rw-r--r--
tests: test using both versions of SSH protocol Now that the version 2 of the SSH protocol is usable in core, we can start actively testing it more widely outside of low-level protocol tests. We add #testcases variants to a handful of tests so we exercise both version 1 and version 2 of the SSH protocol when testing. This will allow us to more easily find regressions and variances as protocol 2 is developed. It will also make it easier to continue testing with protocol version 1 once version 2 is enabled by default. There are a handful of tests using ssh:// that should also gain test variances. One - test-push-race.t - already has a #testcases. This would require combinatorial cases. I didn't want to go down that rabbit hole, so that test is unchanged. Thinking aloud, there is probably an opportunity to automatically run tests with multiple server/protocol implementations. Ideally any test that performed server interaction would run with all supported server implementations and protocols so we could find variances between servers and protocols. But this has been a long-standing issue with our test harness. I don't think it is an easily solved problem. But it would be nice... Differential Revision: https://phab.mercurial-scm.org/D2206

#testcases sshv1 sshv2

#if sshv2
  $ cat >> $HGRCPATH << EOF
  > [experimental]
  > sshpeer.advertise-v2 = true
  > sshserver.support-v2 = true
  > EOF
#endif

  $ cat > bundle2.py << EOF
  > """A small extension to test bundle2 pushback parts.
  > Current bundle2 implementation doesn't provide a way to generate those
  > parts, so they must be created by extensions.
  > """
  > from __future__ import absolute_import
  > from mercurial import bundle2, exchange, pushkey, util
  > def _newhandlechangegroup(op, inpart):
  >     """This function wraps the changegroup part handler for getbundle.
  >     It issues an additional pushkey part to send a new
  >     bookmark back to the client"""
  >     result = bundle2.handlechangegroup(op, inpart)
  >     if 'pushback' in op.reply.capabilities:
  >         params = {'namespace': 'bookmarks',
  >                   'key': 'new-server-mark',
  >                   'old': '',
  >                   'new': 'tip'}
  >         encodedparams = [(k, pushkey.encode(v)) for (k,v) in params.items()]
  >         op.reply.newpart('pushkey', mandatoryparams=encodedparams)
  >     else:
  >         op.reply.newpart('output', data='pushback not enabled')
  >     return result
  > _newhandlechangegroup.params = bundle2.handlechangegroup.params
  > bundle2.parthandlermapping['changegroup'] = _newhandlechangegroup
  > EOF

  $ cat >> $HGRCPATH <<EOF
  > [ui]
  > ssh = $PYTHON "$TESTDIR/dummyssh"
  > username = nobody <no.reply@example.com>
  > 
  > [alias]
  > tglog = log -G -T "{desc} [{phase}:{node|short}]"
  > EOF

Set up server repository

  $ hg init server
  $ cd server
  $ echo c0 > f0
  $ hg commit -Am 0
  adding f0

Set up client repository

  $ cd ..
  $ hg clone ssh://user@dummy/server client -q
  $ cd client

Enable extension
  $ cat >> $HGRCPATH <<EOF
  > [extensions]
  > bundle2=$TESTTMP/bundle2.py
  > EOF

Without config

  $ cd ../client
  $ echo c1 > f1
  $ hg commit -Am 1
  adding f1
  $ hg push
  pushing to ssh://user@dummy/server
  searching for changes
  remote: adding changesets
  remote: adding manifests
  remote: adding file changes
  remote: added 1 changesets with 1 changes to 1 files
  remote: pushback not enabled
  $ hg bookmark
  no bookmarks set

  $ cd ../server
  $ hg tglog
  o  1 [public:2b9c7234e035]
  |
  @  0 [public:6cee5c8f3e5b]
  



With config

  $ cd ../client
  $ echo '[experimental]' >> .hg/hgrc
  $ echo 'bundle2.pushback = True' >> .hg/hgrc
  $ echo c2 > f2
  $ hg commit -Am 2
  adding f2
  $ hg push
  pushing to ssh://user@dummy/server
  searching for changes
  remote: adding changesets
  remote: adding manifests
  remote: adding file changes
  remote: added 1 changesets with 1 changes to 1 files
  $ hg bookmark
     new-server-mark           2:0a76dfb2e179

  $ cd ../server
  $ hg tglog
  o  2 [public:0a76dfb2e179]
  |
  o  1 [public:2b9c7234e035]
  |
  @  0 [public:6cee5c8f3e5b]