Mercurial > hg-stable
annotate tests/test-wireproto-clientreactor.py @ 40129: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 |
rev | line source |
---|---|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 import unittest |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from mercurial import ( |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 error, |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 wireprotoframing as framing, |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 ) |
40129
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
9 from mercurial.utils import ( |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
10 cborutil, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
11 ) |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
13 ffs = framing.makeframefromhumanstring |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
14 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
15 def sendframe(reactor, frame): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
16 """Send a frame bytearray to a reactor.""" |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
17 header = framing.parseheader(frame) |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
18 payload = frame[framing.FRAME_HEADER_SIZE:] |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
19 assert len(payload) == header.length |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
20 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
21 return reactor.onframerecv(framing.frame(header.requestid, |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
22 header.streamid, |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
23 header.streamflags, |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
24 header.typeid, |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
25 header.flags, |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
26 payload)) |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
27 |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 class SingleSendTests(unittest.TestCase): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 """A reactor that can only send once rejects subsequent sends.""" |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
30 |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
31 if not getattr(unittest.TestCase, 'assertRaisesRegex', False): |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
32 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
33 # the regex version. |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
34 assertRaisesRegex = (# camelcase-required |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
35 unittest.TestCase.assertRaisesRegexp) |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
36 |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 def testbasic(self): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 request, action, meta = reactor.callcommand(b'foo', {}) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
41 self.assertEqual(request.state, b'pending') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
42 self.assertEqual(action, b'noop') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 action, meta = reactor.flushcommands() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
45 self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
47 for frame in meta[b'framegen']: |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
48 self.assertEqual(request.state, b'sending') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
50 self.assertEqual(request.state, b'sent') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
52 with self.assertRaisesRegex(error.ProgrammingError, |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 'cannot issue new commands'): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 reactor.callcommand(b'foo', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
56 with self.assertRaisesRegex(error.ProgrammingError, |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 'cannot issue new commands'): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 reactor.callcommand(b'foo', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 class NoBufferTests(unittest.TestCase): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 """A reactor without send buffering sends requests immediately.""" |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 def testbasic(self): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 request, action, meta = reactor.callcommand(b'command1', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 self.assertEqual(request.requestid, 1) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
67 self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
69 self.assertEqual(request.state, b'pending') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
71 for frame in meta[b'framegen']: |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
72 self.assertEqual(request.state, b'sending') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
74 self.assertEqual(request.state, b'sent') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 action, meta = reactor.flushcommands() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
77 self.assertEqual(action, b'noop') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 # And we can send another command. |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 request, action, meta = reactor.callcommand(b'command2', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 self.assertEqual(request.requestid, 3) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
82 self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
84 for frame in meta[b'framegen']: |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
85 self.assertEqual(request.state, b'sending') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
87 self.assertEqual(request.state, b'sent') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
89 class BadFrameRecvTests(unittest.TestCase): |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
90 if not getattr(unittest.TestCase, 'assertRaisesRegex', False): |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
91 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
92 # the regex version. |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
93 assertRaisesRegex = (# camelcase-required |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
94 unittest.TestCase.assertRaisesRegexp) |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
95 |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
96 def testoddstream(self): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
97 reactor = framing.clientreactor() |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
98 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
99 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo')) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
100 self.assertEqual(action, b'error') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
101 self.assertEqual(meta[b'message'], |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
102 b'received frame with odd numbered stream ID: 1') |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
103 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
104 def testunknownstream(self): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
105 reactor = framing.clientreactor() |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
106 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
107 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo')) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
108 self.assertEqual(action, b'error') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
109 self.assertEqual(meta[b'message'], |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
110 b'received frame on unknown stream without beginning ' |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
111 b'of stream flag set') |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
112 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
113 def testunhandledframetype(self): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
114 reactor = framing.clientreactor(buffersends=False) |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
115 |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
116 request, action, meta = reactor.callcommand(b'foo', {}) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
117 for frame in meta[b'framegen']: |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
118 pass |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
119 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
120 with self.assertRaisesRegex(error.ProgrammingError, |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
121 'unhandled frame type'): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
122 sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo')) |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
123 |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
124 class StreamTests(unittest.TestCase): |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
125 def testmultipleresponseframes(self): |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
126 reactor = framing.clientreactor(buffersends=False) |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
127 |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
128 request, action, meta = reactor.callcommand(b'foo', {}) |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
129 |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
130 self.assertEqual(action, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
131 for f in meta[b'framegen']: |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
132 pass |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
133 |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
134 action, meta = sendframe( |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
135 reactor, |
37724
deff7cf7eefd
wireprotov2: change frame type and name for command response
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37715
diff
changeset
|
136 ffs(b'%d 0 stream-begin command-response 0 foo' % |
deff7cf7eefd
wireprotov2: change frame type and name for command response
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37715
diff
changeset
|
137 request.requestid)) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
138 self.assertEqual(action, b'responsedata') |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
139 |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
140 action, meta = sendframe( |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
141 reactor, |
37724
deff7cf7eefd
wireprotov2: change frame type and name for command response
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37715
diff
changeset
|
142 ffs(b'%d 0 0 command-response eos bar' % request.requestid)) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
143 self.assertEqual(action, b'responsedata') |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
144 |
40025
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
145 class RedirectTests(unittest.TestCase): |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
146 def testredirect(self): |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
147 reactor = framing.clientreactor(buffersends=False) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
148 |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
149 redirect = { |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
150 b'targets': [b'a', b'b'], |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
151 b'hashes': [b'sha256'], |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
152 } |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
153 |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
154 request, action, meta = reactor.callcommand( |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
155 b'foo', {}, redirect=redirect) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
156 |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
157 self.assertEqual(action, b'sendframes') |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
158 |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
159 frames = list(meta[b'framegen']) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
160 self.assertEqual(len(frames), 1) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
161 |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
162 self.assertEqual(frames[0], |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
163 ffs(b'1 1 stream-begin command-request new ' |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
164 b"cbor:{b'name': b'foo', " |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
165 b"b'redirect': {b'targets': [b'a', b'b'], " |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
166 b"b'hashes': [b'sha256']}}")) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
167 |
40129
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
168 class StreamSettingsTests(unittest.TestCase): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
169 def testnoflags(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
170 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
171 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
172 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
173 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
174 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
175 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
176 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
177 ffs(b'1 2 stream-begin stream-settings 0 ')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
178 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
179 self.assertEqual(action, b'error') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
180 self.assertEqual(meta, { |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
181 b'message': b'stream encoding settings frame must have ' |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
182 b'continuation or end of stream flag set', |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
183 }) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
184 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
185 def testconflictflags(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
186 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
187 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
188 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
189 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
190 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
191 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
192 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
193 ffs(b'1 2 stream-begin stream-settings continuation|eos ')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
194 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
195 self.assertEqual(action, b'error') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
196 self.assertEqual(meta, { |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
197 b'message': b'stream encoding settings frame cannot have both ' |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
198 b'continuation and end of stream flags set', |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
199 }) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
200 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
201 def testemptypayload(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
202 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
203 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
204 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
205 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
206 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
207 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
208 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
209 ffs(b'1 2 stream-begin stream-settings eos ')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
210 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
211 self.assertEqual(action, b'error') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
212 self.assertEqual(meta, { |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
213 b'message': b'stream encoding settings frame did not contain ' |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
214 b'CBOR data' |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
215 }) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
216 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
217 def testbadcbor(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
218 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
219 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
220 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
221 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
222 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
223 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
224 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
225 ffs(b'1 2 stream-begin stream-settings eos badvalue')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
226 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
227 self.assertEqual(action, b'error') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
228 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
229 def testsingleobject(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
230 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
231 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
232 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
233 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
234 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
235 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
236 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
237 ffs(b'1 2 stream-begin stream-settings eos cbor:b"identity"')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
238 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
239 self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
240 self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
241 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
242 def testmultipleobjects(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
243 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
244 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
245 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
246 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
247 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
248 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
249 data = b''.join([ |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
250 b''.join(cborutil.streamencode(b'identity')), |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
251 b''.join(cborutil.streamencode({b'foo', b'bar'})), |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
252 ]) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
253 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
254 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
255 ffs(b'1 2 stream-begin stream-settings eos %s' % data)) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
256 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
257 self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
258 self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
259 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
260 def testmultipleframes(self): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
261 reactor = framing.clientreactor(buffersends=False) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
262 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
263 request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
264 for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
265 pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
266 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
267 data = b''.join(cborutil.streamencode(b'identity')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
268 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
269 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
270 ffs(b'1 2 stream-begin stream-settings continuation %s' % |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
271 data[0:3])) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
272 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
273 self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
274 self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
275 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
276 action, meta = sendframe(reactor, |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
277 ffs(b'1 2 0 stream-settings eos %s' % data[3:])) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
278 |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
279 self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
280 self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
281 |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 if __name__ == '__main__': |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 import silenttestrunner |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 silenttestrunner.main(__name__) |