author | Manuel Jacob <me@manueljacob.de> |
Fri, 10 Jul 2020 09:59:36 +0200 | |
changeset 45080 | 00cdac669614 |
parent 43076 | 2372284d9457 |
child 45942 | 89a2afe31e82 |
permissions | -rw-r--r-- |
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 |
|
40482
07b87ee2ea75
tests: skip wireproto clientreactor tests on Python 3.6.0-3.6.3 inclusive
Augie Fackler <augie@google.com>
parents:
40132
diff
changeset
|
3 |
import sys |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
import unittest |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
5 |
import zlib |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
from mercurial import ( |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 |
error, |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
9 |
ui as uimod, |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 |
wireprotoframing as framing, |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
12 |
from mercurial.utils import cborutil |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
|
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
14 |
try: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
15 |
from mercurial import zstd |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
16 |
|
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
17 |
zstd.__version__ |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
18 |
except ImportError: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
19 |
zstd = None |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
20 |
|
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
21 |
ffs = framing.makeframefromhumanstring |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
22 |
|
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
23 |
globalui = uimod.ui() |
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
24 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
25 |
|
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
26 |
def sendframe(reactor, frame): |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
27 |
"""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
|
28 |
header = framing.parseheader(frame) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
29 |
payload = frame[framing.FRAME_HEADER_SIZE :] |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
30 |
assert len(payload) == header.length |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
31 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
32 |
return reactor.onframerecv( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
33 |
framing.frame( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
34 |
header.requestid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
35 |
header.streamid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
36 |
header.streamflags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
37 |
header.typeid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
38 |
header.flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
39 |
payload, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
40 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
41 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
42 |
|
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
43 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 |
class SingleSendTests(unittest.TestCase): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
"""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
|
46 |
|
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
47 |
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
|
48 |
# 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
|
49 |
# the regex version. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
50 |
assertRaisesRegex = ( # camelcase-required |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
51 |
unittest.TestCase.assertRaisesRegexp |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
52 |
) |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
53 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
def testbasic(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
55 |
reactor = framing.clientreactor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
56 |
globalui, hasmultiplesend=False, buffersends=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
57 |
) |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
self.assertEqual(action, b'noop') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
action, meta = reactor.flushcommands() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
64 |
self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
66 |
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
|
67 |
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
|
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'sent') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
71 |
with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
72 |
error.ProgrammingError, 'cannot issue new commands' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
73 |
): |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 |
reactor.callcommand(b'foo', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
76 |
with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
77 |
error.ProgrammingError, 'cannot issue new commands' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
78 |
): |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
reactor.callcommand(b'foo', {}) |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
81 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
class NoBufferTests(unittest.TestCase): |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
"""A reactor without send buffering sends requests immediately.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
84 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
def testbasic(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
86 |
reactor = framing.clientreactor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
87 |
globalui, hasmultiplesend=True, buffersends=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
88 |
) |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
94 |
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
|
95 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
99 |
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
|
100 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 |
action, meta = reactor.flushcommands() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
102 |
self.assertEqual(action, b'noop') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 |
|
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 |
# And we can send another command. |
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
self.assertEqual(action, b'sendframes') |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
112 |
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
|
113 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
114 |
|
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
115 |
class BadFrameRecvTests(unittest.TestCase): |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
116 |
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
|
117 |
# 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
|
118 |
# the regex version. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
119 |
assertRaisesRegex = ( # camelcase-required |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
120 |
unittest.TestCase.assertRaisesRegexp |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
121 |
) |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
37682
diff
changeset
|
122 |
|
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
123 |
def testoddstream(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
124 |
reactor = framing.clientreactor(globalui) |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
125 |
|
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
126 |
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
|
127 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
128 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
129 |
meta[b'message'], b'received frame with odd numbered stream ID: 1' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
130 |
) |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
131 |
|
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
132 |
def testunknownstream(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
133 |
reactor = framing.clientreactor(globalui) |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
134 |
|
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
135 |
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
|
136 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
137 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
138 |
meta[b'message'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
139 |
b'received frame on unknown stream without beginning ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
140 |
b'of stream flag set', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
141 |
) |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
142 |
|
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
143 |
def testunhandledframetype(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
144 |
reactor = framing.clientreactor(globalui, buffersends=False) |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
145 |
|
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
pass |
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
149 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
150 |
with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
151 |
error.ProgrammingError, 'unhandled frame type' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
152 |
): |
37544
55b5ba8d4e68
wireproto: client reactor support for receiving frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37543
diff
changeset
|
153 |
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
|
154 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
155 |
|
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
156 |
class StreamTests(unittest.TestCase): |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
157 |
def testmultipleresponseframes(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
158 |
reactor = framing.clientreactor(globalui, buffersends=False) |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
159 |
|
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
160 |
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
|
161 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
162 |
self.assertEqual(action, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
163 |
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
|
164 |
pass |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
165 |
|
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
166 |
action, meta = sendframe( |
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
167 |
reactor, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
168 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
169 |
b'%d 0 stream-begin command-response 0 foo' % request.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
170 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
171 |
) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
172 |
self.assertEqual(action, b'responsedata') |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
173 |
|
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
174 |
action, meta = sendframe( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
175 |
reactor, ffs(b'%d 0 0 command-response eos bar' % request.requestid) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
176 |
) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37656
diff
changeset
|
177 |
self.assertEqual(action, b'responsedata') |
37656
e6870bca1f47
wireprotoframing: record when new stream is encountered
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37544
diff
changeset
|
178 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
179 |
|
40024
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
180 |
class RedirectTests(unittest.TestCase): |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
181 |
def testredirect(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
182 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40024
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
183 |
|
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
184 |
redirect = { |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
185 |
b'targets': [b'a', b'b'], |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
186 |
b'hashes': [b'sha256'], |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
187 |
} |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
188 |
|
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
189 |
request, action, meta = reactor.callcommand( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
190 |
b'foo', {}, redirect=redirect |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
191 |
) |
40024
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
192 |
|
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
193 |
self.assertEqual(action, b'sendframes') |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
194 |
|
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
195 |
frames = list(meta[b'framegen']) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
196 |
self.assertEqual(len(frames), 1) |
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
197 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
198 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
199 |
frames[0], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
200 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
201 |
b'1 1 stream-begin command-request new ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
202 |
b"cbor:{b'name': b'foo', " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
203 |
b"b'redirect': {b'targets': [b'a', b'b'], " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
204 |
b"b'hashes': [b'sha256']}}" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
205 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
206 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
207 |
|
40024
86b22a4cfab1
wireprotov2: client support for advertising redirect targets
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37724
diff
changeset
|
208 |
|
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
209 |
class StreamSettingsTests(unittest.TestCase): |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
210 |
def testnoflags(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
211 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
212 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
213 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
214 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
215 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
216 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
217 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
218 |
reactor, ffs(b'1 2 stream-begin stream-settings 0 ') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
219 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
220 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
221 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
222 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
223 |
meta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
224 |
{ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
225 |
b'message': b'stream encoding settings frame must have ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
226 |
b'continuation or end of stream flag set', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
227 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
228 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
229 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
230 |
def testconflictflags(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
231 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
232 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
233 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
234 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
235 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
236 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
237 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
238 |
reactor, ffs(b'1 2 stream-begin stream-settings continuation|eos ') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
239 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
240 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
241 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
242 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
243 |
meta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
244 |
{ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
245 |
b'message': b'stream encoding settings frame cannot have both ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
246 |
b'continuation and end of stream flags set', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
247 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
248 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
249 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
250 |
def testemptypayload(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
251 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
252 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
253 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
254 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
255 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
256 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
257 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
258 |
reactor, ffs(b'1 2 stream-begin stream-settings eos ') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
259 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
260 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
261 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
262 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
263 |
meta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
264 |
{ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
265 |
b'message': b'stream encoding settings frame did not contain ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
266 |
b'CBOR data' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
267 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
268 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
269 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
270 |
def testbadcbor(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
271 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
272 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
273 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
274 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
275 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
276 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
277 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
278 |
reactor, ffs(b'1 2 stream-begin stream-settings eos badvalue') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
279 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
280 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
281 |
self.assertEqual(action, b'error') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
282 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
283 |
def testsingleobject(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
284 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
285 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
286 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
287 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
288 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
289 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
290 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
291 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
292 |
ffs(b'1 2 stream-begin stream-settings eos cbor:b"identity"'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
293 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
294 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
295 |
self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
296 |
self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
297 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
298 |
def testmultipleobjects(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
299 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
300 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
301 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
302 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
303 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
304 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
305 |
data = b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
306 |
[ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
307 |
b''.join(cborutil.streamencode(b'identity')), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
308 |
b''.join(cborutil.streamencode({b'foo', b'bar'})), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
309 |
] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
310 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
311 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
312 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
313 |
reactor, ffs(b'1 2 stream-begin stream-settings eos %s' % data) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
314 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
315 |
|
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
316 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
317 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
318 |
meta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
319 |
{ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
320 |
b'message': b'error setting stream decoder: identity decoder ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
321 |
b'received unexpected additional values', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
322 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
323 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
324 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
325 |
def testmultipleframes(self): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40128
diff
changeset
|
326 |
reactor = framing.clientreactor(globalui, buffersends=False) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
327 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
328 |
request, action, meta = reactor.callcommand(b'foo', {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
329 |
for f in meta[b'framegen']: |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
330 |
pass |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
331 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
332 |
data = b''.join(cborutil.streamencode(b'identity')) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
333 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
334 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
335 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
336 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
337 |
b'1 2 stream-begin stream-settings continuation %s' % data[0:3] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
338 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
339 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
340 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
341 |
self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
342 |
self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
343 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
344 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
345 |
reactor, ffs(b'1 2 0 stream-settings eos %s' % data[3:]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
346 |
) |
40128
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
347 |
|
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
348 |
self.assertEqual(action, b'noop') |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
349 |
self.assertEqual(meta, {}) |
57782791b7e9
wireprotov2: handle stream encoding settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40024
diff
changeset
|
350 |
|
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
351 |
def testinvalidencoder(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
352 |
reactor = framing.clientreactor(globalui, buffersends=False) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
353 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
354 |
request, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
355 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
356 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
357 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
358 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
359 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
360 |
ffs(b'1 2 stream-begin stream-settings eos cbor:b"badvalue"'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
361 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
362 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
363 |
self.assertEqual(action, b'error') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
364 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
365 |
meta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
366 |
{ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
367 |
b'message': b'error setting stream decoder: unknown stream ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
368 |
b'decoder: badvalue', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
369 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
370 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
371 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
372 |
def testzlibencoding(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
373 |
reactor = framing.clientreactor(globalui, buffersends=False) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
374 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
375 |
request, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
376 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
377 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
378 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
379 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
380 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
381 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
382 |
b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
383 |
% request.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
384 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
385 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
386 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
387 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
388 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
389 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
390 |
result = { |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
391 |
b'status': b'ok', |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
392 |
} |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
393 |
encoded = b''.join(cborutil.streamencode(result)) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
394 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
395 |
compressed = zlib.compress(encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
396 |
self.assertEqual(zlib.decompress(compressed), encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
397 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
398 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
399 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
400 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
401 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
402 |
% (request.requestid, compressed) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
403 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
404 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
405 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
406 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
407 |
self.assertEqual(meta[b'data'], encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
408 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
409 |
def testzlibencodingsinglebyteframes(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
410 |
reactor = framing.clientreactor(globalui, buffersends=False) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
411 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
412 |
request, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
413 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
414 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
415 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
416 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
417 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
418 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
419 |
b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
420 |
% request.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
421 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
422 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
423 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
424 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
425 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
426 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
427 |
result = { |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
428 |
b'status': b'ok', |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
429 |
} |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
430 |
encoded = b''.join(cborutil.streamencode(result)) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
431 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
432 |
compressed = zlib.compress(encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
433 |
self.assertEqual(zlib.decompress(compressed), encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
434 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
435 |
chunks = [] |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
436 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
437 |
for i in range(len(compressed)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
438 |
char = compressed[i : i + 1] |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
439 |
if char == b'\\': |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
440 |
char = b'\\\\' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
441 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
442 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
443 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
444 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
445 |
% (request.requestid, char) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
446 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
447 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
448 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
449 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
450 |
chunks.append(meta[b'data']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
451 |
self.assertTrue(meta[b'expectmore']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
452 |
self.assertFalse(meta[b'eos']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
453 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
454 |
# zlib will have the full data decoded at this point, even though |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
455 |
# we haven't flushed. |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
456 |
self.assertEqual(b''.join(chunks), encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
457 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
458 |
# End the stream for good measure. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
459 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
460 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
461 |
ffs(b'%d 2 stream-end command-response eos ' % request.requestid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
462 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
463 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
464 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
465 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
466 |
self.assertFalse(meta[b'expectmore']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
467 |
self.assertTrue(meta[b'eos']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
468 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
469 |
def testzlibmultipleresponses(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
470 |
# We feed in zlib compressed data on the same stream but belonging to |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
471 |
# 2 different requests. This tests our flushing behavior. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
472 |
reactor = framing.clientreactor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
473 |
globalui, buffersends=False, hasmultiplesend=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
474 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
475 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
476 |
request1, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
477 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
478 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
479 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
480 |
request2, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
481 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
482 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
483 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
484 |
outstream = framing.outputstream(2) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
485 |
outstream.setencoder(globalui, b'zlib') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
486 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
487 |
response1 = b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
488 |
cborutil.streamencode( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
489 |
{b'status': b'ok', b'extra': b'response1' * 10,} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
490 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
491 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
492 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
493 |
response2 = b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
494 |
cborutil.streamencode( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
495 |
{b'status': b'error', b'extra': b'response2' * 10,} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
496 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
497 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
498 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
499 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
500 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
501 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
502 |
b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
503 |
% request1.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
504 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
505 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
506 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
507 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
508 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
509 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
510 |
# Feeding partial data in won't get anything useful out. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
511 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
512 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
513 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
514 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
515 |
% (request1.requestid, outstream.encode(response1)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
516 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
517 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
518 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
519 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
520 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
521 |
# But flushing data at both ends will get our original data. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
522 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
523 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
524 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
525 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
526 |
% (request1.requestid, outstream.flush()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
527 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
528 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
529 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
530 |
self.assertEqual(meta[b'data'], response1) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
531 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
532 |
# We should be able to reuse the compressor/decompressor for the |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
533 |
# 2nd response. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
534 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
535 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
536 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
537 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
538 |
% (request2.requestid, outstream.encode(response2)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
539 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
540 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
541 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
542 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
543 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
544 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
545 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
546 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
547 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
548 |
% (request2.requestid, outstream.flush()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
549 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
550 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
551 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
552 |
self.assertEqual(meta[b'data'], response2) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
553 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
554 |
@unittest.skipUnless(zstd, 'zstd not available') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
555 |
def testzstd8mbencoding(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
556 |
reactor = framing.clientreactor(globalui, buffersends=False) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
557 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
558 |
request, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
559 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
560 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
561 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
562 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
563 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
564 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
565 |
b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
566 |
% request.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
567 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
568 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
569 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
570 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
571 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
572 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
573 |
result = { |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
574 |
b'status': b'ok', |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
575 |
} |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
576 |
encoded = b''.join(cborutil.streamencode(result)) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
577 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
578 |
encoder = framing.zstd8mbencoder(globalui) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
579 |
compressed = encoder.encode(encoded) + encoder.finish() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
580 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
581 |
zstd.ZstdDecompressor().decompress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
582 |
compressed, max_output_size=len(encoded) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
583 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
584 |
encoded, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
585 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
586 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
587 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
588 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
589 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
590 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
591 |
% (request.requestid, compressed) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
592 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
593 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
594 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
595 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
596 |
self.assertEqual(meta[b'data'], encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
597 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
598 |
@unittest.skipUnless(zstd, 'zstd not available') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
599 |
def testzstd8mbencodingsinglebyteframes(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
600 |
reactor = framing.clientreactor(globalui, buffersends=False) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
601 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
602 |
request, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
603 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
604 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
605 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
606 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
607 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
608 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
609 |
b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
610 |
% request.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
611 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
612 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
613 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
614 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
615 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
616 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
617 |
result = { |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
618 |
b'status': b'ok', |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
619 |
} |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
620 |
encoded = b''.join(cborutil.streamencode(result)) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
621 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
622 |
compressed = zstd.ZstdCompressor().compress(encoded) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
623 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
624 |
zstd.ZstdDecompressor().decompress(compressed), encoded |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
625 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
626 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
627 |
chunks = [] |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
628 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
629 |
for i in range(len(compressed)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
630 |
char = compressed[i : i + 1] |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
631 |
if char == b'\\': |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
632 |
char = b'\\\\' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
633 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
634 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
635 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
636 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
637 |
% (request.requestid, char) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
638 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
639 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
640 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
641 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
642 |
chunks.append(meta[b'data']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
643 |
self.assertTrue(meta[b'expectmore']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
644 |
self.assertFalse(meta[b'eos']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
645 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
646 |
# zstd decompressor will flush at frame boundaries. |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
647 |
self.assertEqual(b''.join(chunks), encoded) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
648 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
649 |
# End the stream for good measure. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
650 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
651 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
652 |
ffs(b'%d 2 stream-end command-response eos ' % request.requestid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
653 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
654 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
655 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
656 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
657 |
self.assertFalse(meta[b'expectmore']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
658 |
self.assertTrue(meta[b'eos']) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
659 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
660 |
@unittest.skipUnless(zstd, 'zstd not available') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
661 |
def testzstd8mbmultipleresponses(self): |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
662 |
# We feed in zstd compressed data on the same stream but belonging to |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
663 |
# 2 different requests. This tests our flushing behavior. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
664 |
reactor = framing.clientreactor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
665 |
globalui, buffersends=False, hasmultiplesend=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
666 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
667 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
668 |
request1, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
669 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
670 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
671 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
672 |
request2, action, meta = reactor.callcommand(b'foo', {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
673 |
for f in meta[b'framegen']: |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
674 |
pass |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
675 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
676 |
outstream = framing.outputstream(2) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
677 |
outstream.setencoder(globalui, b'zstd-8mb') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
678 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
679 |
response1 = b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
680 |
cborutil.streamencode( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
681 |
{b'status': b'ok', b'extra': b'response1' * 10,} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
682 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
683 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
684 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
685 |
response2 = b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
686 |
cborutil.streamencode( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
687 |
{b'status': b'error', b'extra': b'response2' * 10,} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
688 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
689 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
690 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
691 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
692 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
693 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
694 |
b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
695 |
% request1.requestid |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
696 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
697 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
698 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
699 |
self.assertEqual(action, b'noop') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
700 |
self.assertEqual(meta, {}) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
701 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
702 |
# Feeding partial data in won't get anything useful out. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
703 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
704 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
705 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
706 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
707 |
% (request1.requestid, outstream.encode(response1)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
708 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
709 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
710 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
711 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
712 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
713 |
# But flushing data at both ends will get our original data. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
714 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
715 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
716 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
717 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
718 |
% (request1.requestid, outstream.flush()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
719 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
720 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
721 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
722 |
self.assertEqual(meta[b'data'], response1) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
723 |
|
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
724 |
# We should be able to reuse the compressor/decompressor for the |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
725 |
# 2nd response. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
726 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
727 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
728 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
729 |
b'%d 2 encoded command-response continuation %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
730 |
% (request2.requestid, outstream.encode(response2)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
731 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
732 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
733 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
734 |
self.assertEqual(meta[b'data'], b'') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
735 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
736 |
action, meta = sendframe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
737 |
reactor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
738 |
ffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
739 |
b'%d 2 encoded command-response eos %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
740 |
% (request2.requestid, outstream.flush()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
741 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
742 |
) |
40132
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
743 |
self.assertEqual(action, b'responsedata') |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
744 |
self.assertEqual(meta[b'data'], response2) |
e67522413ca8
wireprotov2: define and use stream encoders
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
745 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
746 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
747 |
if __name__ == '__main__': |
41119
685cf59a134f
tests: correct version check in clientreactor test
Augie Fackler <raf@durin42.com>
parents:
40482
diff
changeset
|
748 |
if (3, 6, 0) <= sys.version_info < (3, 6, 4): |
40482
07b87ee2ea75
tests: skip wireproto clientreactor tests on Python 3.6.0-3.6.3 inclusive
Augie Fackler <augie@google.com>
parents:
40132
diff
changeset
|
749 |
# Python 3.6.0 through 3.6.3 inclusive shipped with |
07b87ee2ea75
tests: skip wireproto clientreactor tests on Python 3.6.0-3.6.3 inclusive
Augie Fackler <augie@google.com>
parents:
40132
diff
changeset
|
750 |
# https://bugs.python.org/issue31825 and we can't run these |
07b87ee2ea75
tests: skip wireproto clientreactor tests on Python 3.6.0-3.6.3 inclusive
Augie Fackler <augie@google.com>
parents:
40132
diff
changeset
|
751 |
# tests on those specific versions of Python. Sigh. |
07b87ee2ea75
tests: skip wireproto clientreactor tests on Python 3.6.0-3.6.3 inclusive
Augie Fackler <augie@google.com>
parents:
40132
diff
changeset
|
752 |
sys.exit(80) |
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
753 |
import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41119
diff
changeset
|
754 |
|
37543
01361be9e2dc
wireproto: introduce a reactor for client-side state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
755 |
silenttestrunner.main(__name__) |