author | Martin von Zweigbergk <martinvonz@google.com> |
Fri, 10 May 2019 21:55:59 -0700 | |
changeset 42295 | fdd4d668ceb5 |
parent 41136 | a181a1c8af1d |
child 43076 | 2372284d9457 |
permissions | -rw-r--r-- |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import, print_function |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 |
import unittest |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
from mercurial import ( |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40126
diff
changeset
|
6 |
ui as uimod, |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
util, |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 |
wireprotoframing as framing, |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
) |
40126
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
10 |
from mercurial.utils import ( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
11 |
cborutil, |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
12 |
) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 |
ffs = framing.makeframefromhumanstring |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 |
|
41136
a181a1c8af1d
tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents:
40138
diff
changeset
|
16 |
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
|
17 |
|
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
18 |
def makereactor(deferoutput=False): |
40129
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40126
diff
changeset
|
19 |
ui = uimod.ui() |
293835e0fff7
wireprotov2: pass ui into clientreactor and serverreactor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40126
diff
changeset
|
20 |
return framing.serverreactor(ui, deferoutput=deferoutput) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 |
def sendframes(reactor, gen): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 |
"""Send a generator of frame bytearray to a reactor. |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
Emits a generator of results from ``onframerecv()`` calls. |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
""" |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
for frame in gen: |
37061
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
28 |
header = framing.parseheader(frame) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
payload = frame[framing.FRAME_HEADER_SIZE:] |
37061
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
30 |
assert len(payload) == header.length |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
|
37061
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
32 |
yield reactor.onframerecv(framing.frame(header.requestid, |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
33 |
header.streamid, |
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
34 |
header.streamflags, |
37061
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
35 |
header.typeid, |
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
36 |
header.flags, |
884a0c1604ad
wireproto: define attr-based classes for representing frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37060
diff
changeset
|
37 |
payload)) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 |
|
37285
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
39 |
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
|
40 |
"""Generate frames to run a command and send them to a reactor.""" |
37057
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
41 |
return sendframes(reactor, |
37285
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
42 |
framing.createcommandframes(stream, rid, cmd, args, |
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
43 |
datafh)) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 |
|
37060
0a6c5cc09a88
wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37058
diff
changeset
|
45 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
class ServerReactorTests(unittest.TestCase): |
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
47 |
def _sendsingleframe(self, reactor, f): |
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
48 |
results = list(sendframes(reactor, [f])) |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
self.assertEqual(len(results), 1) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
return results[0] |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
def assertaction(self, res, expected): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
self.assertIsInstance(res, tuple) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
self.assertEqual(len(res), 2) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 |
self.assertIsInstance(res[1], dict) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 |
self.assertEqual(res[0], expected) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
|
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
59 |
def assertframesequal(self, frames, framestrings): |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
60 |
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
|
61 |
self.assertEqual(list(frames), expected) |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
62 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
def test1framecommand(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
"""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
|
65 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
self.assertaction(results[0], b'runcommand') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
self.assertEqual(results[0][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
71 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
72 |
b'command': b'mycommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
73 |
b'args': {}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
74 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
75 |
b'data': None, |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 |
|
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
78 |
result = reactor.oninputeof() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
79 |
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
|
80 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
def test1argument(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
83 |
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
|
84 |
results = list(sendcommandframes(reactor, stream, 41, b'mycommand', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
{b'foo': b'bar'})) |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
86 |
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
|
87 |
self.assertaction(results[0], b'runcommand') |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
88 |
self.assertEqual(results[0][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
89 |
b'requestid': 41, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
90 |
b'command': b'mycommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
91 |
b'args': {b'foo': b'bar'}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
92 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
93 |
b'data': None, |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 |
def testmultiarguments(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
{b'foo': b'bar', b'biz': b'baz'})) |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
101 |
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
|
102 |
self.assertaction(results[0], b'runcommand') |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
103 |
self.assertEqual(results[0][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
104 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
105 |
b'command': b'mycommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
106 |
b'args': {b'foo': b'bar', b'biz': b'baz'}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
107 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
108 |
b'data': None, |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 |
def testsimplecommanddata(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
util.bytesio(b'data!'))) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
self.assertaction(results[1], b'runcommand') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
self.assertEqual(results[1][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
120 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
121 |
b'command': b'mycommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
122 |
b'args': {}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
123 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
124 |
b'data': b'data!', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
def testmultipledataframes(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
frames = [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
129 |
ffs(b'1 1 stream-begin command-request new|have-data ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
130 |
b"cbor:{b'name': b'mycommand'}"), |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
] |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 |
reactor = makereactor() |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 |
results = list(sendframes(reactor, frames)) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 |
self.assertEqual(len(results), 4) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
self.assertaction(results[3], b'runcommand') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 |
self.assertEqual(results[3][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
143 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
144 |
b'command': b'mycommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
145 |
b'args': {}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
146 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
147 |
b'data': b'data1data2data3', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 |
def testargumentanddata(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
frames = [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
152 |
ffs(b'1 1 stream-begin command-request new|have-data ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
153 |
b"cbor:{b'name': b'command', b'args': {b'key': b'val'," |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
154 |
b"b'foo': b'bar'}}"), |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
] |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 |
reactor = makereactor() |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
results = list(sendframes(reactor, frames)) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
162 |
self.assertaction(results[-1], b'runcommand') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 |
self.assertEqual(results[-1][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
164 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
165 |
b'command': b'command', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
166 |
b'args': { |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 |
b'key': b'val', |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
b'foo': b'bar', |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 |
}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
170 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
171 |
b'data': b'value1value2', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 |
|
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
174 |
def testnewandcontinuation(self): |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
175 |
result = self._sendsingleframe(makereactor(), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
176 |
ffs(b'1 1 stream-begin command-request new|continuation ')) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
177 |
self.assertaction(result, b'error') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 |
self.assertEqual(result[1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
179 |
b'message': b'received command request frame with both new and ' |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
180 |
b'continuation flags set', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
|
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
183 |
def testneithernewnorcontinuation(self): |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
184 |
result = self._sendsingleframe(makereactor(), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
185 |
ffs(b'1 1 stream-begin command-request 0 ')) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
186 |
self.assertaction(result, b'error') |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
187 |
self.assertEqual(result[1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
188 |
b'message': b'received command request frame with neither new nor ' |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
189 |
b'continuation flags set', |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
190 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
191 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 |
def testunexpectedcommanddata(self): |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
193 |
"""Command data frame when not running a command is an error.""" |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
194 |
result = self._sendsingleframe(makereactor(), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
195 |
ffs(b'1 1 stream-begin command-data 0 ignored')) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
196 |
self.assertaction(result, b'error') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 |
self.assertEqual(result[1], { |
40126
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
198 |
b'message': b'expected sender protocol settings or command request ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
199 |
b'frame; got 2', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 |
|
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
202 |
def testunexpectedcommanddatareceiving(self): |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
203 |
"""Same as above except the command is receiving.""" |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
204 |
results = list(sendframes(makereactor(), [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
205 |
ffs(b'1 1 stream-begin command-request new|more ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
206 |
b"cbor:{b'name': b'ignored'}"), |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
207 |
ffs(b'1 1 0 command-data eos ignored'), |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
208 |
])) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
209 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
210 |
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
|
211 |
self.assertaction(results[1], b'error') |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
212 |
self.assertEqual(results[1][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
213 |
b'message': b'received command data frame for request that is not ' |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
214 |
b'expecting data: 1', |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
215 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
216 |
|
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
217 |
def testconflictingrequestidallowed(self): |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
218 |
"""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
|
219 |
reactor = makereactor() |
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
220 |
results = [] |
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
221 |
outstream = reactor.makeoutputstream() |
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
222 |
results.append(self._sendsingleframe( |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
223 |
reactor, ffs(b'1 1 stream-begin command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
224 |
b"cbor:{b'name': b'command'}"))) |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
225 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
226 |
outstream, 1, [b'response1']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
227 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
228 |
list(result[1][b'framegen']) |
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
229 |
results.append(self._sendsingleframe( |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
230 |
reactor, ffs(b'1 1 stream-begin command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
231 |
b"cbor:{b'name': b'command'}"))) |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
232 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
233 |
outstream, 1, [b'response2']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
234 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
235 |
list(result[1][b'framegen']) |
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
236 |
results.append(self._sendsingleframe( |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
237 |
reactor, ffs(b'1 1 stream-begin command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
238 |
b"cbor:{b'name': b'command'}"))) |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
239 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
240 |
outstream, 1, [b'response3']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
241 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
242 |
list(result[1][b'framegen']) |
37284
12bfc724217d
tests: fix duplicate and failing test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37063
diff
changeset
|
243 |
|
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
244 |
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
|
245 |
self.assertaction(results[i], b'runcommand') |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
246 |
self.assertEqual(results[i][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
247 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
248 |
b'command': b'command', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
249 |
b'args': {}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
250 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
251 |
b'data': None, |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
252 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
253 |
|
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
254 |
def testconflictingrequestid(self): |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
255 |
"""Request ID for new command matching in-flight command is illegal.""" |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
256 |
results = list(sendframes(makereactor(), [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
257 |
ffs(b'1 1 stream-begin command-request new|more ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
258 |
b"cbor:{b'name': b'command'}"), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
259 |
ffs(b'1 1 0 command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
260 |
b"cbor:{b'name': b'command1'}"), |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
261 |
])) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
262 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
263 |
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
|
264 |
self.assertaction(results[1], b'error') |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
265 |
self.assertEqual(results[1][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
266 |
b'message': b'request with ID 1 already received', |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
267 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
268 |
|
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
269 |
def testinterleavedcommands(self): |
41136
a181a1c8af1d
tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents:
40138
diff
changeset
|
270 |
cbor1 = b''.join(cborutil.streamencode({ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
271 |
b'name': b'command1', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
272 |
b'args': { |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
273 |
b'foo': b'bar', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
274 |
b'key1': b'val', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
275 |
} |
41136
a181a1c8af1d
tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents:
40138
diff
changeset
|
276 |
})) |
a181a1c8af1d
tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents:
40138
diff
changeset
|
277 |
cbor3 = b''.join(cborutil.streamencode({ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
278 |
b'name': b'command3', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
279 |
b'args': { |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
280 |
b'biz': b'baz', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
281 |
b'key': b'val', |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
282 |
}, |
41136
a181a1c8af1d
tests: migrate test-wireproto-serverreactor.py to our internal CBOR
Augie Fackler <augie@google.com>
parents:
40138
diff
changeset
|
283 |
})) |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
284 |
|
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
285 |
results = list(sendframes(makereactor(), [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
286 |
ffs(b'1 1 stream-begin command-request new|more %s' % cbor1[0:6]), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
287 |
ffs(b'3 1 0 command-request new|more %s' % cbor3[0:10]), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
288 |
ffs(b'1 1 0 command-request continuation|more %s' % cbor1[6:9]), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
289 |
ffs(b'3 1 0 command-request continuation|more %s' % cbor3[10:13]), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
290 |
ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
291 |
ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]), |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
292 |
])) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
293 |
|
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
294 |
self.assertEqual([t[0] for t in results], [ |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
295 |
b'wantframe', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
296 |
b'wantframe', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
297 |
b'wantframe', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
298 |
b'wantframe', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
299 |
b'runcommand', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
300 |
b'runcommand', |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
301 |
]) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
302 |
|
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
303 |
self.assertEqual(results[4][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
304 |
b'requestid': 3, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
305 |
b'command': b'command3', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
306 |
b'args': {b'biz': b'baz', b'key': b'val'}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
307 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
308 |
b'data': None, |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
309 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
310 |
self.assertEqual(results[5][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
311 |
b'requestid': 1, |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
312 |
b'command': b'command1', |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
313 |
b'args': {b'foo': b'bar', b'key1': b'val'}, |
40025
b099e6032f38
wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37726
diff
changeset
|
314 |
b'redirect': None, |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
315 |
b'data': None, |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
316 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
317 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 |
def testmissingcommanddataframe(self): |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
319 |
# 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
|
320 |
# 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
|
321 |
frames = [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
322 |
ffs(b'1 1 stream-begin command-request new|have-data ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
323 |
b"cbor:{b'name': b'command1'}"), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
324 |
ffs(b'3 1 0 command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
325 |
b"cbor:{b'name': b'command2'}"), |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 |
] |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 |
results = list(sendframes(makereactor(), frames)) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
self.assertaction(results[1], b'runcommand') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
|
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 |
def testmissingcommanddataframeflags(self): |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
333 |
frames = [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
334 |
ffs(b'1 1 stream-begin command-request new|have-data ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
335 |
b"cbor:{b'name': b'command1'}"), |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
336 |
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
|
337 |
] |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 |
results = list(sendframes(makereactor(), frames)) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 |
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
|
340 |
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
|
341 |
self.assertaction(results[1], b'error') |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 |
self.assertEqual(results[1][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
343 |
b'message': b'command data frame without flags', |
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 |
}) |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 |
|
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
346 |
def testframefornonreceivingrequest(self): |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
347 |
"""Receiving a frame for a command that is not receiving is illegal.""" |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
348 |
results = list(sendframes(makereactor(), [ |
37292
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
349 |
ffs(b'1 1 stream-begin command-request new ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
350 |
b"cbor:{b'name': b'command1'}"), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
351 |
ffs(b'3 1 0 command-request new|have-data ' |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
352 |
b"cbor:{b'name': b'command3'}"), |
3d0e2cd86e05
wireproto: use CBOR for command requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37290
diff
changeset
|
353 |
ffs(b'5 1 0 command-data eos ignored'), |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
354 |
])) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
355 |
self.assertaction(results[2], b'error') |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
356 |
self.assertEqual(results[2][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
357 |
b'message': b'received frame for request that is not receiving: 5', |
37058
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
358 |
}) |
c5e9c3b47366
wireproto: support for receiving multiple requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37057
diff
changeset
|
359 |
|
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
360 |
def testsimpleresponse(self): |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
361 |
"""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
|
362 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
363 |
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
|
364 |
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
|
365 |
|
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
366 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
367 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
368 |
outstream, 1, [b'response']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
369 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
370 |
self.assertframesequal(result[1][b'framegen'], [ |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
371 |
b'1 2 stream-begin stream-settings eos cbor:b"identity"', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
372 |
b'1 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
373 |
b'1 2 encoded command-response continuation cbor:b"response"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
374 |
b'1 2 0 command-response eos ', |
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
375 |
]) |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
376 |
|
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
377 |
def testmultiframeresponse(self): |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
378 |
"""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
|
379 |
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
|
380 |
second = b'y' * 100 |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
381 |
|
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
382 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
383 |
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
|
384 |
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
|
385 |
|
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
386 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
387 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
388 |
outstream, 1, [first + second]) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
389 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
390 |
self.assertframesequal(result[1][b'framegen'], [ |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
391 |
b'1 2 stream-begin stream-settings eos cbor:b"identity"', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
392 |
b'1 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
393 |
b'1 2 encoded command-response continuation Y\x80d', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
394 |
b'1 2 encoded command-response continuation %s' % first, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
395 |
b'1 2 encoded command-response continuation %s' % second, |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
396 |
b'1 2 0 command-response eos ' |
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
397 |
]) |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
398 |
|
37726
0c184ca594bb
wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37725
diff
changeset
|
399 |
def testservererror(self): |
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
400 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
401 |
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
|
402 |
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
|
403 |
|
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
404 |
outstream = reactor.makeoutputstream() |
37726
0c184ca594bb
wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37725
diff
changeset
|
405 |
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
|
406 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
407 |
self.assertframesequal(result[1][b'framegen'], [ |
37726
0c184ca594bb
wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37725
diff
changeset
|
408 |
b"1 2 stream-begin error-response 0 " |
0c184ca594bb
wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37725
diff
changeset
|
409 |
b"cbor:{b'type': b'server', " |
0c184ca594bb
wireprotov2: change behavior of error frame
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37725
diff
changeset
|
410 |
b"b'message': [{b'msg': b'some message'}]}", |
37055
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
411 |
]) |
61393f888dfe
wireproto: define and implement responses in framing protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37052
diff
changeset
|
412 |
|
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
413 |
def test1commanddeferresponse(self): |
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
414 |
"""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
|
415 |
reactor = makereactor(deferoutput=True) |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
416 |
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
|
417 |
results = list(sendcommandframes(reactor, instream, 1, b'mycommand', |
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
418 |
{})) |
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
419 |
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
|
420 |
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
|
421 |
|
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
422 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
423 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
424 |
outstream, 1, [b'response']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
425 |
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
|
426 |
result = reactor.oninputeof() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
427 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
428 |
self.assertframesequal(result[1][b'framegen'], [ |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
429 |
b'1 2 stream-begin stream-settings eos cbor:b"identity"', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
430 |
b'1 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
431 |
b'1 2 encoded command-response continuation cbor:b"response"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
432 |
b'1 2 0 command-response eos ', |
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
433 |
]) |
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
434 |
|
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
435 |
def testmultiplecommanddeferresponse(self): |
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
436 |
reactor = makereactor(deferoutput=True) |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
|
37289
5fadc63ac99f
wireproto: explicit API to create outgoing streams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37288
diff
changeset
|
441 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
442 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
443 |
outstream, 1, [b'response1']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
444 |
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
|
445 |
result = reactor.oncommandresponsereadyobjects( |
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
446 |
outstream, 3, [b'response2']) |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
447 |
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
|
448 |
result = reactor.oninputeof() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
449 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
450 |
self.assertframesequal(result[1][b'framegen'], [ |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
451 |
b'1 2 stream-begin stream-settings eos cbor:b"identity"', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
452 |
b'1 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
453 |
b'1 2 encoded command-response continuation cbor:b"response1"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
454 |
b'1 2 0 command-response eos ', |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
455 |
b'3 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
456 |
b'3 2 encoded command-response continuation cbor:b"response2"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
457 |
b'3 2 0 command-response eos ', |
37057
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
458 |
]) |
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
459 |
|
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
460 |
def testrequestidtracking(self): |
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
461 |
reactor = makereactor(deferoutput=True) |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
462 |
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
|
463 |
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
|
464 |
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
|
465 |
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
|
466 |
|
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
467 |
# 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
|
468 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
469 |
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
|
470 |
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
|
471 |
reactor.oncommandresponsereadyobjects(outstream, 5, [b'response5']) |
37057
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
472 |
|
2ec1fb9de638
wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37056
diff
changeset
|
473 |
result = reactor.oninputeof() |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
474 |
self.assertaction(result, b'sendframes') |
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
475 |
self.assertframesequal(result[1][b'framegen'], [ |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
476 |
b'3 2 stream-begin stream-settings eos cbor:b"identity"', |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
477 |
b'3 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
478 |
b'3 2 encoded command-response continuation cbor:b"response3"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
479 |
b'3 2 0 command-response eos ', |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
480 |
b'1 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
481 |
b'1 2 encoded command-response continuation cbor:b"response1"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
482 |
b'1 2 0 command-response eos ', |
40138
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
483 |
b'5 2 encoded command-response continuation %s' % OK, |
b5bf3dd6ec5b
wireprotov2: send content encoded frames from server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40136
diff
changeset
|
484 |
b'5 2 encoded command-response continuation cbor:b"response5"', |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
485 |
b'5 2 0 command-response eos ', |
37056
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
486 |
]) |
861e9d37e56e
wireproto: buffer output frames when in half duplex mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37055
diff
changeset
|
487 |
|
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
488 |
def testduplicaterequestonactivecommand(self): |
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
489 |
"""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
|
490 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
|
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
495 |
self.assertaction(results[0], b'error') |
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
496 |
self.assertEqual(results[0][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
497 |
b'message': b'request with ID 1 is already active', |
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
498 |
}) |
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
499 |
|
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
500 |
def testduplicaterequestonactivecommandnosend(self): |
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
501 |
"""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
|
502 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
506 |
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
|
507 |
|
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
508 |
# 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
|
509 |
# 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
|
510 |
|
37285
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
511 |
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
|
512 |
self.assertaction(results[0], b'error') |
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
513 |
self.assertEqual(results[0][1], { |
37682
cb71e0f9ac6f
tests: add all missing b prefixes in reactor tests
Augie Fackler <augie@google.com>
parents:
37542
diff
changeset
|
514 |
b'message': b'request with ID 1 is already active', |
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
515 |
}) |
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
516 |
|
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
517 |
def testduplicaterequestaftersend(self): |
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
518 |
"""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
|
519 |
reactor = makereactor() |
37288
9bfcbe4f4745
wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37285
diff
changeset
|
520 |
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
|
521 |
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
|
522 |
outstream = reactor.makeoutputstream() |
40135
966b5f7fd30b
wireprotov2: remove functions for creating response frames from bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40129
diff
changeset
|
523 |
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
|
524 |
list(res[1][b'framegen']) |
37063
39304dd63589
wireproto: explicitly track which requests are active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37061
diff
changeset
|
525 |
|
37285
3ed344546d9e
wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37284
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
|
40126
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
529 |
def testprotocolsettingsnoflags(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
530 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
531 |
makereactor(), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
532 |
ffs(b'0 1 stream-begin sender-protocol-settings 0 ')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
533 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
534 |
self.assertEqual(result[1], { |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
535 |
b'message': b'sender protocol settings frame must have ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
536 |
b'continuation or end of stream flag set', |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
537 |
}) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
538 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
539 |
def testprotocolsettingsconflictflags(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
540 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
541 |
makereactor(), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
542 |
ffs(b'0 1 stream-begin sender-protocol-settings continuation|eos ')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
543 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
544 |
self.assertEqual(result[1], { |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
545 |
b'message': b'sender protocol settings frame cannot have both ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
546 |
b'continuation and end of stream flags set', |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
547 |
}) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
548 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
549 |
def testprotocolsettingsemptypayload(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
550 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
551 |
makereactor(), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
552 |
ffs(b'0 1 stream-begin sender-protocol-settings eos ')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
553 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
554 |
self.assertEqual(result[1], { |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
555 |
b'message': b'sender protocol settings frame did not contain CBOR ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
556 |
b'data', |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
557 |
}) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
558 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
559 |
def testprotocolsettingsmultipleobjects(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
560 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
561 |
makereactor(), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
562 |
ffs(b'0 1 stream-begin sender-protocol-settings eos ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
563 |
b'\x46foobar\x43foo')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
564 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
565 |
self.assertEqual(result[1], { |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
566 |
b'message': b'sender protocol settings frame contained multiple ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
567 |
b'CBOR values', |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
568 |
}) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
569 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
570 |
def testprotocolsettingscontentencodings(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
571 |
reactor = makereactor() |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
572 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
573 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
574 |
reactor, |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
575 |
ffs(b'0 1 stream-begin sender-protocol-settings eos ' |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
576 |
b'cbor:{b"contentencodings": [b"a", b"b"]}')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
577 |
self.assertaction(result, b'wantframe') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
578 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
579 |
self.assertEqual(reactor._state, b'idle') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
580 |
self.assertEqual(reactor._sendersettings[b'contentencodings'], |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
581 |
[b'a', b'b']) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
582 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
583 |
def testprotocolsettingsmultipleframes(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
584 |
reactor = makereactor() |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
585 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
586 |
data = b''.join(cborutil.streamencode({ |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
587 |
b'contentencodings': [b'value1', b'value2'], |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
588 |
})) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
589 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
590 |
results = list(sendframes(reactor, [ |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
591 |
ffs(b'0 1 stream-begin sender-protocol-settings continuation %s' % |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
592 |
data[0:5]), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
593 |
ffs(b'0 1 0 sender-protocol-settings eos %s' % data[5:]), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
594 |
])) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
595 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
596 |
self.assertEqual(len(results), 2) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
597 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
598 |
self.assertaction(results[0], b'wantframe') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
599 |
self.assertaction(results[1], b'wantframe') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
600 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
601 |
self.assertEqual(reactor._state, b'idle') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
602 |
self.assertEqual(reactor._sendersettings[b'contentencodings'], |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
603 |
[b'value1', b'value2']) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
604 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
605 |
def testprotocolsettingsbadcbor(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
606 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
607 |
makereactor(), |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
608 |
ffs(b'0 1 stream-begin sender-protocol-settings eos badvalue')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
609 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
610 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
611 |
def testprotocolsettingsnoninitial(self): |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
612 |
# 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
|
613 |
reactor = makereactor() |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
614 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
615 |
stream = framing.stream(1) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
616 |
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
|
617 |
self.assertEqual(len(results), 1) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
618 |
self.assertaction(results[0], b'runcommand') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
619 |
|
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
620 |
result = self._sendsingleframe( |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
621 |
reactor, |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
622 |
ffs(b'0 1 0 sender-protocol-settings eos ')) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
623 |
self.assertaction(result, b'error') |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
624 |
self.assertEqual(result[1], { |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
625 |
b'message': b'expected command request frame; got 8', |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
626 |
}) |
327d40b94bed
wireprotov2: handle sender protocol settings frames
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40025
diff
changeset
|
627 |
|
37052
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 |
if __name__ == '__main__': |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 |
import silenttestrunner |
8c3c47362934
wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
630 |
silenttestrunner.main(__name__) |