annotate tests/test-wireproto-clientreactor.py @ 46209:a51d345f1404

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