annotate tests/test-wireproto-clientreactor.py @ 49487:e8481625c582

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