Mercurial > public > mercurial-scm > hg
diff tests/test-wireproto-clientreactor.py @ 40128:57782791b7e9
wireprotov2: handle stream encoding settings frames
Like what we just did for the server reactor, we teach the client
reactor to handle stream encoding settings frames. The code is
very similar.
We define a method on the stream class to handle processing the data
within the decoded frames. However, it doesn't yet do anything useful.
Differential Revision: https://phab.mercurial-scm.org/D4918
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 04 Oct 2018 16:44:21 -0700 |
parents | 86b22a4cfab1 |
children | 293835e0fff7 |
line wrap: on
line diff
--- a/tests/test-wireproto-clientreactor.py Thu Oct 04 15:43:21 2018 -0700 +++ b/tests/test-wireproto-clientreactor.py Thu Oct 04 16:44:21 2018 -0700 @@ -6,6 +6,9 @@ error, wireprotoframing as framing, ) +from mercurial.utils import ( + cborutil, +) ffs = framing.makeframefromhumanstring @@ -162,6 +165,120 @@ b"b'redirect': {b'targets': [b'a', b'b'], " b"b'hashes': [b'sha256']}}")) +class StreamSettingsTests(unittest.TestCase): + def testnoflags(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings 0 ')) + + self.assertEqual(action, b'error') + self.assertEqual(meta, { + b'message': b'stream encoding settings frame must have ' + b'continuation or end of stream flag set', + }) + + def testconflictflags(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings continuation|eos ')) + + self.assertEqual(action, b'error') + self.assertEqual(meta, { + b'message': b'stream encoding settings frame cannot have both ' + b'continuation and end of stream flags set', + }) + + def testemptypayload(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings eos ')) + + self.assertEqual(action, b'error') + self.assertEqual(meta, { + b'message': b'stream encoding settings frame did not contain ' + b'CBOR data' + }) + + def testbadcbor(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings eos badvalue')) + + self.assertEqual(action, b'error') + + def testsingleobject(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings eos cbor:b"identity"')) + + self.assertEqual(action, b'noop') + self.assertEqual(meta, {}) + + def testmultipleobjects(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + data = b''.join([ + b''.join(cborutil.streamencode(b'identity')), + b''.join(cborutil.streamencode({b'foo', b'bar'})), + ]) + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings eos %s' % data)) + + self.assertEqual(action, b'noop') + self.assertEqual(meta, {}) + + def testmultipleframes(self): + reactor = framing.clientreactor(buffersends=False) + + request, action, meta = reactor.callcommand(b'foo', {}) + for f in meta[b'framegen']: + pass + + data = b''.join(cborutil.streamencode(b'identity')) + + action, meta = sendframe(reactor, + ffs(b'1 2 stream-begin stream-settings continuation %s' % + data[0:3])) + + self.assertEqual(action, b'noop') + self.assertEqual(meta, {}) + + action, meta = sendframe(reactor, + ffs(b'1 2 0 stream-settings eos %s' % data[3:])) + + self.assertEqual(action, b'noop') + self.assertEqual(meta, {}) + if __name__ == '__main__': import silenttestrunner silenttestrunner.main(__name__)