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