annotate tests/test-wireproto-serverreactor.py @ 48326:141e38ef8d8f stable

tests: dd status=noxfer is not portable (issue6523) Differential Revision: https://phab.mercurial-scm.org/D11754
author Thomas Klausner <wiz@gatalith.at>
date Mon, 15 Nov 2021 12:03:28 +0100
parents 89a2afe31e82
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 from __future__ import absolute_import, print_function
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 import unittest
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 from mercurial import (
40129
293835e0fff7 wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40126
diff changeset
6 ui as uimod,
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7 util,
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 wireprotoframing as framing,
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
10 from mercurial.utils import cborutil
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 ffs = framing.makeframefromhumanstring
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13
41136
a181a1c8af1d tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents: 40138
diff changeset
14 OK = b''.join(cborutil.streamencode({b'status': b'ok'}))
37725
3ea8323d6f95 wireprotov2: change command response protocol to include a leading map
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37724
diff changeset
15
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
16
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
17 def makereactor(deferoutput=False):
40129
293835e0fff7 wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40126
diff changeset
18 ui = uimod.ui()
293835e0fff7 wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40126
diff changeset
19 return framing.serverreactor(ui, deferoutput=deferoutput)
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
21
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22 def sendframes(reactor, gen):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23 """Send a generator of frame bytearray to a reactor.
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 Emits a generator of results from ``onframerecv()`` calls.
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 """
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 for frame in gen:
37061
884a0c1604ad wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37060
diff changeset
28 header = framing.parseheader(frame)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
29 payload = frame[framing.FRAME_HEADER_SIZE :]
37061
884a0c1604ad wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37060
diff changeset
30 assert len(payload) == header.length
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
32 yield reactor.onframerecv(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
33 framing.frame(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
34 header.requestid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
35 header.streamid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
36 header.streamflags,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
37 header.typeid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
38 header.flags,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
39 payload,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
40 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
41 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
42
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
43
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
44 def sendcommandframes(reactor, stream, rid, cmd, args, datafh=None):
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
45 """Generate frames to run a command and send them to a reactor."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
46 return sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
47 reactor, framing.createcommandframes(stream, rid, cmd, args, datafh)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
48 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
50
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
51 class ServerReactorTests(unittest.TestCase):
37284
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
52 def _sendsingleframe(self, reactor, f):
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
53 results = list(sendframes(reactor, [f]))
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
54 self.assertEqual(len(results), 1)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
55
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 return results[0]
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
57
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
58 def assertaction(self, res, expected):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
59 self.assertIsInstance(res, tuple)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
60 self.assertEqual(len(res), 2)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
61 self.assertIsInstance(res[1], dict)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62 self.assertEqual(res[0], expected)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
64 def assertframesequal(self, frames, framestrings):
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
65 expected = [ffs(s) for s in framestrings]
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
66 self.assertEqual(list(frames), expected)
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
67
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
68 def test1framecommand(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
69 """Receiving a command in a single frame yields request to run it."""
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
70 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
71 stream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
72 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}))
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 self.assertEqual(len(results), 1)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
74 self.assertaction(results[0], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
75 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
76 results[0][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
77 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
78 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
79 b'command': b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
80 b'args': {},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
81 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
82 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
83 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
84 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
86 result = reactor.oninputeof()
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
87 self.assertaction(result, b'noop')
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
88
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
89 def test1argument(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
91 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
92 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
93 sendcommandframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
94 reactor, stream, 41, b'mycommand', {b'foo': b'bar'}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
95 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
96 )
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
97 self.assertEqual(len(results), 1)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
98 self.assertaction(results[0], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
99 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
100 results[0][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
101 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
102 b'requestid': 41,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
103 b'command': b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
104 b'args': {b'foo': b'bar'},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
105 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
106 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
107 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
108 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
109
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
110 def testmultiarguments(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
111 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
112 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
113 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
114 sendcommandframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
115 reactor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
116 stream,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
117 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
118 b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
119 {b'foo': b'bar', b'biz': b'baz'},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
120 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
121 )
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
122 self.assertEqual(len(results), 1)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
123 self.assertaction(results[0], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
124 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
125 results[0][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
126 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
127 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
128 b'command': b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
129 b'args': {b'foo': b'bar', b'biz': b'baz'},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
130 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
131 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
132 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
133 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135 def testsimplecommanddata(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
136 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
137 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
138 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
139 sendcommandframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
140 reactor, stream, 1, b'mycommand', {}, util.bytesio(b'data!')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
141 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
142 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
143 self.assertEqual(len(results), 2)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
144 self.assertaction(results[0], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
145 self.assertaction(results[1], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
146 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
147 results[1][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
148 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
149 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
150 b'command': b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
151 b'args': {},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
152 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
153 b'data': b'data!',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
154 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
155 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
156
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
157 def testmultipledataframes(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
158 frames = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
159 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
160 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
161 b"cbor:{b'name': b'mycommand'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
162 ),
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
163 ffs(b'1 1 0 command-data continuation data1'),
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
164 ffs(b'1 1 0 command-data continuation data2'),
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
165 ffs(b'1 1 0 command-data eos data3'),
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
166 ]
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
167
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
168 reactor = makereactor()
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
169 results = list(sendframes(reactor, frames))
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
170 self.assertEqual(len(results), 4)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
171 for i in range(3):
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
172 self.assertaction(results[i], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
173 self.assertaction(results[3], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
174 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
175 results[3][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
176 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
177 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
178 b'command': b'mycommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
179 b'args': {},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
180 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
181 b'data': b'data1data2data3',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
182 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
183 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
184
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
185 def testargumentanddata(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
186 frames = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
187 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
188 b'1 1 stream-begin command-request new|have-data '
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
189 b"cbor:{b'name': b'command', b'args': {b'key': b'val',"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
190 b"b'foo': b'bar'}}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
191 ),
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
192 ffs(b'1 1 0 command-data continuation value1'),
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
193 ffs(b'1 1 0 command-data eos value2'),
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
194 ]
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
195
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
196 reactor = makereactor()
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
197 results = list(sendframes(reactor, frames))
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
198
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
199 self.assertaction(results[-1], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
200 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
201 results[-1][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
202 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
203 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
204 b'command': b'command',
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
205 b'args': {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
206 b'key': b'val',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
207 b'foo': b'bar',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
208 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
209 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
210 b'data': b'value1value2',
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
211 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
212 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
213
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
214 def testnewandcontinuation(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
215 result = self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
216 makereactor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
217 ffs(b'1 1 stream-begin command-request new|continuation '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
218 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
219 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
220 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
221 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
222 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
223 b'message': b'received command request frame with both new and '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
224 b'continuation flags set',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
225 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
226 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
227
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
228 def testneithernewnorcontinuation(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
229 result = self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
230 makereactor(), ffs(b'1 1 stream-begin command-request 0 ')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
231 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
232 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
233 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
234 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
235 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
236 b'message': b'received command request frame with neither new nor '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
237 b'continuation flags set',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
238 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
239 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
240
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
241 def testunexpectedcommanddata(self):
37292
3d0e2cd86e05 wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37290
diff changeset
242 """Command data frame when not running a command is an error."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
243 result = self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
244 makereactor(), ffs(b'1 1 stream-begin command-data 0 ignored')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
245 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
246 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
247 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
248 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
249 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
250 b'message': b'expected sender protocol settings or command request '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
251 b'frame; got 2',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
252 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
253 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
254
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
255 def testunexpectedcommanddatareceiving(self):
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
256 """Same as above except the command is receiving."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
257 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
258 sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
259 makereactor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
260 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
261 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
262 b'1 1 stream-begin command-request new|more '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
263 b"cbor:{b'name': b'ignored'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
264 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
265 ffs(b'1 1 0 command-data eos ignored'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
266 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
267 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
268 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
269
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
270 self.assertaction(results[0], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
271 self.assertaction(results[1], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
272 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
273 results[1][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
274 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
275 b'message': b'received command data frame for request that is not '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
276 b'expecting data: 1',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
277 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
278 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
279
37284
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
280 def testconflictingrequestidallowed(self):
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
281 """Multiple fully serviced commands with same request ID is allowed."""
37284
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
282 reactor = makereactor()
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
283 results = []
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
284 outstream = reactor.makeoutputstream()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
285 results.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
286 self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
287 reactor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
288 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
289 b'1 1 stream-begin command-request new '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
290 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
291 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
292 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
293 )
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
294 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
295 outstream, 1, [b'response1']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
296 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
297 self.assertaction(result, b'sendframes')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
298 list(result[1][b'framegen'])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
299 results.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
300 self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
301 reactor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
302 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
303 b'1 1 stream-begin command-request new '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
304 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
305 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
306 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
307 )
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
308 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
309 outstream, 1, [b'response2']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
310 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
311 self.assertaction(result, b'sendframes')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
312 list(result[1][b'framegen'])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
313 results.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
314 self._sendsingleframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
315 reactor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
316 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
317 b'1 1 stream-begin command-request new '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
318 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
319 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
320 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
321 )
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
322 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
323 outstream, 1, [b'response3']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
324 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
325 self.assertaction(result, b'sendframes')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
326 list(result[1][b'framegen'])
37284
12bfc724217d tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37063
diff changeset
327
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
328 for i in range(3):
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
329 self.assertaction(results[i], b'runcommand')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
330 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
331 results[i][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
332 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
333 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
334 b'command': b'command',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
335 b'args': {},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
336 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
337 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
338 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
339 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
340
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
341 def testconflictingrequestid(self):
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
342 """Request ID for new command matching in-flight command is illegal."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
343 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
344 sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
345 makereactor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
346 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
347 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
348 b'1 1 stream-begin command-request new|more '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
349 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
350 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
351 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
352 b'1 1 0 command-request new '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
353 b"cbor:{b'name': b'command1'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
354 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
355 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
356 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
357 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
358
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
359 self.assertaction(results[0], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
360 self.assertaction(results[1], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
361 self.assertEqual(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
362 results[1][1],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
363 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
364 b'message': b'request with ID 1 already received',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
365 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
366 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
367
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
368 def testinterleavedcommands(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
369 cbor1 = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
370 cborutil.streamencode(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
371 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
372 b'name': b'command1',
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
373 b'args': {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
374 b'foo': b'bar',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
375 b'key1': b'val',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
376 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
377 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
378 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
379 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
380 cbor3 = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
381 cborutil.streamencode(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
382 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
383 b'name': b'command3',
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
384 b'args': {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
385 b'biz': b'baz',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
386 b'key': b'val',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
387 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
388 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
389 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
390 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
391
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
392 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
393 sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
394 makereactor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
395 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
396 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
397 b'1 1 stream-begin command-request new|more %s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
398 % cbor1[0:6]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
399 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
400 ffs(b'3 1 0 command-request new|more %s' % cbor3[0:10]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
401 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
402 b'1 1 0 command-request continuation|more %s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
403 % cbor1[6:9]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
404 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
405 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
406 b'3 1 0 command-request continuation|more %s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
407 % cbor3[10:13]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
408 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
409 ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
410 ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
411 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
412 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
413 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
414
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
415 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
416 [t[0] for t in results],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
417 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
418 b'wantframe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
419 b'wantframe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
420 b'wantframe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
421 b'wantframe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
422 b'runcommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
423 b'runcommand',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
424 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
425 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
426
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
427 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
428 results[4][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
429 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
430 b'requestid': 3,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
431 b'command': b'command3',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
432 b'args': {b'biz': b'baz', b'key': b'val'},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
433 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
434 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
435 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
436 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
437 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
438 results[5][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
439 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
440 b'requestid': 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
441 b'command': b'command1',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
442 b'args': {b'foo': b'bar', b'key1': b'val'},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
443 b'redirect': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
444 b'data': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
445 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
446 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
447
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
448 def testmissingcommanddataframe(self):
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
449 # The reactor doesn't currently handle partially received commands.
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
450 # So this test is failing to do anything with request 1.
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
451 frames = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
452 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
453 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
454 b"cbor:{b'name': b'command1'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
455 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
456 ffs(b'3 1 0 command-request new ' b"cbor:{b'name': b'command2'}"),
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
457 ]
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
458 results = list(sendframes(makereactor(), frames))
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
459 self.assertEqual(len(results), 2)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
460 self.assertaction(results[0], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
461 self.assertaction(results[1], b'runcommand')
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
462
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
463 def testmissingcommanddataframeflags(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
464 frames = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
465 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
466 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
467 b"cbor:{b'name': b'command1'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
468 ),
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
469 ffs(b'1 1 0 command-data 0 data'),
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
470 ]
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
471 results = list(sendframes(makereactor(), frames))
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
472 self.assertEqual(len(results), 2)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
473 self.assertaction(results[0], b'wantframe')
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
474 self.assertaction(results[1], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
475 self.assertEqual(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
476 results[1][1],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
477 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
478 b'message': b'command data frame without flags',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
479 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
480 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
481
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
482 def testframefornonreceivingrequest(self):
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
483 """Receiving a frame for a command that is not receiving is illegal."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
484 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
485 sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
486 makereactor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
487 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
488 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
489 b'1 1 stream-begin command-request new '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
490 b"cbor:{b'name': b'command1'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
491 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
492 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
493 b'3 1 0 command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
494 b"cbor:{b'name': b'command3'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
495 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
496 ffs(b'5 1 0 command-data eos ignored'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
497 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
498 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
499 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
500 self.assertaction(results[2], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
501 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
502 results[2][1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
503 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
504 b'message': b'received frame for request that is not receiving: 5',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
505 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
506 )
37058
c5e9c3b47366 wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37057
diff changeset
507
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
508 def testsimpleresponse(self):
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
509 """Bytes response to command sends result frames."""
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
510 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
511 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
512 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
513
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
514 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
515 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
516 outstream, 1, [b'response']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
517 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
518 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
519 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
520 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
521 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
522 b'1 2 stream-begin stream-settings eos cbor:b"identity"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
523 b'1 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
524 b'1 2 encoded command-response continuation cbor:b"response"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
525 b'1 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
526 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
527 )
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
528
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
529 def testmultiframeresponse(self):
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
530 """Bytes response spanning multiple frames is handled."""
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
531 first = b'x' * framing.DEFAULT_MAX_FRAME_SIZE
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
532 second = b'y' * 100
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
533
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
534 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
535 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
536 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
537
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
538 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
539 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
540 outstream, 1, [first + second]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
541 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
542 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
543 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
544 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
545 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
546 b'1 2 stream-begin stream-settings eos cbor:b"identity"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
547 b'1 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
548 b'1 2 encoded command-response continuation Y\x80d',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
549 b'1 2 encoded command-response continuation %s' % first,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
550 b'1 2 encoded command-response continuation %s' % second,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
551 b'1 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
552 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
553 )
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
554
37726
0c184ca594bb wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37725
diff changeset
555 def testservererror(self):
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
556 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
557 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
558 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
559
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
560 outstream = reactor.makeoutputstream()
37726
0c184ca594bb wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37725
diff changeset
561 result = reactor.onservererror(outstream, 1, b'some message')
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
562 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
563 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
564 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
565 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
566 b"1 2 stream-begin error-response 0 "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
567 b"cbor:{b'type': b'server', "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
568 b"b'message': [{b'msg': b'some message'}]}",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
569 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
570 )
37055
61393f888dfe wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37052
diff changeset
571
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
572 def test1commanddeferresponse(self):
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
573 """Responses when in deferred output mode are delayed until EOF."""
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
574 reactor = makereactor(deferoutput=True)
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
575 instream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
576 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
577 sendcommandframes(reactor, instream, 1, b'mycommand', {})
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
578 )
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
579 self.assertEqual(len(results), 1)
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
580 self.assertaction(results[0], b'runcommand')
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
581
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
582 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
583 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
584 outstream, 1, [b'response']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
585 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
586 self.assertaction(result, b'noop')
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
587 result = reactor.oninputeof()
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
588 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
589 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
590 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
591 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
592 b'1 2 stream-begin stream-settings eos cbor:b"identity"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
593 b'1 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
594 b'1 2 encoded command-response continuation cbor:b"response"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
595 b'1 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
596 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
597 )
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
598
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
599 def testmultiplecommanddeferresponse(self):
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
600 reactor = makereactor(deferoutput=True)
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
601 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
602 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
603 list(sendcommandframes(reactor, instream, 3, b'command2', {}))
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
604
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
605 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
606 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
607 outstream, 1, [b'response1']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
608 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
609 self.assertaction(result, b'noop')
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
610 result = reactor.oncommandresponsereadyobjects(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
611 outstream, 3, [b'response2']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
612 )
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
613 self.assertaction(result, b'noop')
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
614 result = reactor.oninputeof()
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
615 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
616 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
617 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
618 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
619 b'1 2 stream-begin stream-settings eos cbor:b"identity"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
620 b'1 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
621 b'1 2 encoded command-response continuation cbor:b"response1"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
622 b'1 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
623 b'3 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
624 b'3 2 encoded command-response continuation cbor:b"response2"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
625 b'3 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
626 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
627 )
37057
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
628
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
629 def testrequestidtracking(self):
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
630 reactor = makereactor(deferoutput=True)
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
631 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
632 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
633 list(sendcommandframes(reactor, instream, 3, b'command2', {}))
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
634 list(sendcommandframes(reactor, instream, 5, b'command3', {}))
37057
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
635
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
636 # Register results for commands out of order.
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
637 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
638 reactor.oncommandresponsereadyobjects(outstream, 3, [b'response3'])
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
639 reactor.oncommandresponsereadyobjects(outstream, 1, [b'response1'])
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
640 reactor.oncommandresponsereadyobjects(outstream, 5, [b'response5'])
37057
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
641
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37056
diff changeset
642 result = reactor.oninputeof()
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
643 self.assertaction(result, b'sendframes')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
644 self.assertframesequal(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
645 result[1][b'framegen'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
646 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
647 b'3 2 stream-begin stream-settings eos cbor:b"identity"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
648 b'3 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
649 b'3 2 encoded command-response continuation cbor:b"response3"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
650 b'3 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
651 b'1 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
652 b'1 2 encoded command-response continuation cbor:b"response1"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
653 b'1 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
654 b'5 2 encoded command-response continuation %s' % OK,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
655 b'5 2 encoded command-response continuation cbor:b"response5"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
656 b'5 2 0 command-response eos ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
657 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
658 )
37056
861e9d37e56e wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37055
diff changeset
659
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
660 def testduplicaterequestonactivecommand(self):
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
661 """Receiving a request ID that matches a request that isn't finished."""
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
662 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
663 stream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
664 list(sendcommandframes(reactor, stream, 1, b'command1', {}))
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
665 results = list(sendcommandframes(reactor, stream, 1, b'command1', {}))
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
666
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
667 self.assertaction(results[0], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
668 self.assertEqual(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
669 results[0][1],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
670 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
671 b'message': b'request with ID 1 is already active',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
672 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
673 )
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
674
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
675 def testduplicaterequestonactivecommandnosend(self):
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
676 """Same as above but we've registered a response but haven't sent it."""
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
677 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
678 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
679 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
680 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
681 reactor.oncommandresponsereadyobjects(outstream, 1, [b'response'])
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
682
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
683 # We've registered the response but haven't sent it. From the
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
684 # perspective of the reactor, the command is still active.
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
685
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
686 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
687 self.assertaction(results[0], b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
688 self.assertEqual(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
689 results[0][1],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
690 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
691 b'message': b'request with ID 1 is already active',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
692 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
693 )
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
694
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
695 def testduplicaterequestaftersend(self):
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
696 """We can use a duplicate request ID after we've sent the response."""
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
697 reactor = makereactor()
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
698 instream = framing.stream(1)
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
699 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
37289
5fadc63ac99f wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
700 outstream = reactor.makeoutputstream()
40135
966b5f7fd30b wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40129
diff changeset
701 res = reactor.oncommandresponsereadyobjects(outstream, 1, [b'response'])
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
702 list(res[1][b'framegen'])
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
703
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
704 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
37682
cb71e0f9ac6f tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
705 self.assertaction(results[0], b'runcommand')
37063
39304dd63589 wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37061
diff changeset
706
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
707 def testprotocolsettingsnoflags(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
708 result = self._sendsingleframe(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
709 makereactor(), ffs(b'0 1 stream-begin sender-protocol-settings 0 ')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
710 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
711 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
712 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
713 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
714 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
715 b'message': b'sender protocol settings frame must have '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
716 b'continuation or end of stream flag set',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
717 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
718 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
719
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
720 def testprotocolsettingsconflictflags(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
721 result = self._sendsingleframe(
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
722 makereactor(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
723 ffs(b'0 1 stream-begin sender-protocol-settings continuation|eos '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
724 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
725 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
726 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
727 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
728 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
729 b'message': b'sender protocol settings frame cannot have both '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
730 b'continuation and end of stream flags set',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
731 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
732 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
733
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
734 def testprotocolsettingsemptypayload(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
735 result = self._sendsingleframe(
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
736 makereactor(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
737 ffs(b'0 1 stream-begin sender-protocol-settings eos '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
738 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
739 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
740 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
741 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
742 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
743 b'message': b'sender protocol settings frame did not contain CBOR '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
744 b'data',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
745 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
746 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
747
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
748 def testprotocolsettingsmultipleobjects(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
749 result = self._sendsingleframe(
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
750 makereactor(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
751 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
752 b'0 1 stream-begin sender-protocol-settings eos '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
753 b'\x46foobar\x43foo'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
754 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
755 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
756 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
757 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
758 result[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
759 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
760 b'message': b'sender protocol settings frame contained multiple '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
761 b'CBOR values',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
762 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
763 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
764
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
765 def testprotocolsettingscontentencodings(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
766 reactor = makereactor()
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
767
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
768 result = self._sendsingleframe(
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
769 reactor,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
770 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
771 b'0 1 stream-begin sender-protocol-settings eos '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
772 b'cbor:{b"contentencodings": [b"a", b"b"]}'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
773 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
774 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
775 self.assertaction(result, b'wantframe')
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
776
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
777 self.assertEqual(reactor._state, b'idle')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
778 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
779 reactor._sendersettings[b'contentencodings'], [b'a', b'b']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
780 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
781
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
782 def testprotocolsettingsmultipleframes(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
783 reactor = makereactor()
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
784
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
785 data = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
786 cborutil.streamencode(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
787 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
788 b'contentencodings': [b'value1', b'value2'],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
789 }
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
790 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
791 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
792
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
793 results = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
794 sendframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
795 reactor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
796 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
797 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
798 b'0 1 stream-begin sender-protocol-settings continuation %s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
799 % data[0:5]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
800 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
801 ffs(b'0 1 0 sender-protocol-settings eos %s' % data[5:]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
802 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
803 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
804 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
805
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
806 self.assertEqual(len(results), 2)
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
807
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
808 self.assertaction(results[0], b'wantframe')
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
809 self.assertaction(results[1], b'wantframe')
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
810
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
811 self.assertEqual(reactor._state, b'idle')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
812 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
813 reactor._sendersettings[b'contentencodings'], [b'value1', b'value2']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
814 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
815
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
816 def testprotocolsettingsbadcbor(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
817 result = self._sendsingleframe(
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
818 makereactor(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
819 ffs(b'0 1 stream-begin sender-protocol-settings eos badvalue'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
820 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
821 self.assertaction(result, b'error')
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
822
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
823 def testprotocolsettingsnoninitial(self):
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
824 # Cannot have protocol settings frames as non-initial frames.
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
825 reactor = makereactor()
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
826
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
827 stream = framing.stream(1)
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
828 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}))
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
829 self.assertEqual(len(results), 1)
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
830 self.assertaction(results[0], b'runcommand')
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
831
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
832 result = self._sendsingleframe(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
833 reactor, ffs(b'0 1 0 sender-protocol-settings eos ')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
834 )
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
835 self.assertaction(result, b'error')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
836 self.assertEqual(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
837 result[1],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
838 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
839 b'message': b'expected command request frame; got 8',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
840 },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
841 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
842
40126
327d40b94bed wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40025
diff changeset
843
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
844 if __name__ == '__main__':
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
845 import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41136
diff changeset
846
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
847 silenttestrunner.main(__name__)