comparison tests/test-wireproto-serverreactor.py @ 37682:cb71e0f9ac6f

tests: add all missing b prefixes in reactor tests Both of these tests now pass on Python 3. # skip-blame just b prefixes. So many b prefixes. Differential Revision: https://phab.mercurial-scm.org/D3369
author Augie Fackler <augie@google.com>
date Sat, 14 Apr 2018 01:35:44 -0400
parents 1ec5ce21cb46
children e8fba6d578f0
comparison
equal deleted inserted replaced
37681:3942bd8db8b2 37682:cb71e0f9ac6f
60 """Receiving a command in a single frame yields request to run it.""" 60 """Receiving a command in a single frame yields request to run it."""
61 reactor = makereactor() 61 reactor = makereactor()
62 stream = framing.stream(1) 62 stream = framing.stream(1)
63 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {})) 63 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}))
64 self.assertEqual(len(results), 1) 64 self.assertEqual(len(results), 1)
65 self.assertaction(results[0], 'runcommand') 65 self.assertaction(results[0], b'runcommand')
66 self.assertEqual(results[0][1], { 66 self.assertEqual(results[0][1], {
67 'requestid': 1, 67 b'requestid': 1,
68 'command': b'mycommand', 68 b'command': b'mycommand',
69 'args': {}, 69 b'args': {},
70 'data': None, 70 b'data': None,
71 }) 71 })
72 72
73 result = reactor.oninputeof() 73 result = reactor.oninputeof()
74 self.assertaction(result, 'noop') 74 self.assertaction(result, b'noop')
75 75
76 def test1argument(self): 76 def test1argument(self):
77 reactor = makereactor() 77 reactor = makereactor()
78 stream = framing.stream(1) 78 stream = framing.stream(1)
79 results = list(sendcommandframes(reactor, stream, 41, b'mycommand', 79 results = list(sendcommandframes(reactor, stream, 41, b'mycommand',
80 {b'foo': b'bar'})) 80 {b'foo': b'bar'}))
81 self.assertEqual(len(results), 1) 81 self.assertEqual(len(results), 1)
82 self.assertaction(results[0], 'runcommand') 82 self.assertaction(results[0], b'runcommand')
83 self.assertEqual(results[0][1], { 83 self.assertEqual(results[0][1], {
84 'requestid': 41, 84 b'requestid': 41,
85 'command': b'mycommand', 85 b'command': b'mycommand',
86 'args': {b'foo': b'bar'}, 86 b'args': {b'foo': b'bar'},
87 'data': None, 87 b'data': None,
88 }) 88 })
89 89
90 def testmultiarguments(self): 90 def testmultiarguments(self):
91 reactor = makereactor() 91 reactor = makereactor()
92 stream = framing.stream(1) 92 stream = framing.stream(1)
93 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', 93 results = list(sendcommandframes(reactor, stream, 1, b'mycommand',
94 {b'foo': b'bar', b'biz': b'baz'})) 94 {b'foo': b'bar', b'biz': b'baz'}))
95 self.assertEqual(len(results), 1) 95 self.assertEqual(len(results), 1)
96 self.assertaction(results[0], 'runcommand') 96 self.assertaction(results[0], b'runcommand')
97 self.assertEqual(results[0][1], { 97 self.assertEqual(results[0][1], {
98 'requestid': 1, 98 b'requestid': 1,
99 'command': b'mycommand', 99 b'command': b'mycommand',
100 'args': {b'foo': b'bar', b'biz': b'baz'}, 100 b'args': {b'foo': b'bar', b'biz': b'baz'},
101 'data': None, 101 b'data': None,
102 }) 102 })
103 103
104 def testsimplecommanddata(self): 104 def testsimplecommanddata(self):
105 reactor = makereactor() 105 reactor = makereactor()
106 stream = framing.stream(1) 106 stream = framing.stream(1)
107 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}, 107 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {},
108 util.bytesio(b'data!'))) 108 util.bytesio(b'data!')))
109 self.assertEqual(len(results), 2) 109 self.assertEqual(len(results), 2)
110 self.assertaction(results[0], 'wantframe') 110 self.assertaction(results[0], b'wantframe')
111 self.assertaction(results[1], 'runcommand') 111 self.assertaction(results[1], b'runcommand')
112 self.assertEqual(results[1][1], { 112 self.assertEqual(results[1][1], {
113 'requestid': 1, 113 b'requestid': 1,
114 'command': b'mycommand', 114 b'command': b'mycommand',
115 'args': {}, 115 b'args': {},
116 'data': b'data!', 116 b'data': b'data!',
117 }) 117 })
118 118
119 def testmultipledataframes(self): 119 def testmultipledataframes(self):
120 frames = [ 120 frames = [
121 ffs(b'1 1 stream-begin command-request new|have-data ' 121 ffs(b'1 1 stream-begin command-request new|have-data '
127 127
128 reactor = makereactor() 128 reactor = makereactor()
129 results = list(sendframes(reactor, frames)) 129 results = list(sendframes(reactor, frames))
130 self.assertEqual(len(results), 4) 130 self.assertEqual(len(results), 4)
131 for i in range(3): 131 for i in range(3):
132 self.assertaction(results[i], 'wantframe') 132 self.assertaction(results[i], b'wantframe')
133 self.assertaction(results[3], 'runcommand') 133 self.assertaction(results[3], b'runcommand')
134 self.assertEqual(results[3][1], { 134 self.assertEqual(results[3][1], {
135 'requestid': 1, 135 b'requestid': 1,
136 'command': b'mycommand', 136 b'command': b'mycommand',
137 'args': {}, 137 b'args': {},
138 'data': b'data1data2data3', 138 b'data': b'data1data2data3',
139 }) 139 })
140 140
141 def testargumentanddata(self): 141 def testargumentanddata(self):
142 frames = [ 142 frames = [
143 ffs(b'1 1 stream-begin command-request new|have-data ' 143 ffs(b'1 1 stream-begin command-request new|have-data '
148 ] 148 ]
149 149
150 reactor = makereactor() 150 reactor = makereactor()
151 results = list(sendframes(reactor, frames)) 151 results = list(sendframes(reactor, frames))
152 152
153 self.assertaction(results[-1], 'runcommand') 153 self.assertaction(results[-1], b'runcommand')
154 self.assertEqual(results[-1][1], { 154 self.assertEqual(results[-1][1], {
155 'requestid': 1, 155 b'requestid': 1,
156 'command': b'command', 156 b'command': b'command',
157 'args': { 157 b'args': {
158 b'key': b'val', 158 b'key': b'val',
159 b'foo': b'bar', 159 b'foo': b'bar',
160 }, 160 },
161 'data': b'value1value2', 161 b'data': b'value1value2',
162 }) 162 })
163 163
164 def testnewandcontinuation(self): 164 def testnewandcontinuation(self):
165 result = self._sendsingleframe(makereactor(), 165 result = self._sendsingleframe(makereactor(),
166 ffs(b'1 1 stream-begin command-request new|continuation ')) 166 ffs(b'1 1 stream-begin command-request new|continuation '))
167 self.assertaction(result, 'error') 167 self.assertaction(result, b'error')
168 self.assertEqual(result[1], { 168 self.assertEqual(result[1], {
169 'message': b'received command request frame with both new and ' 169 b'message': b'received command request frame with both new and '
170 b'continuation flags set', 170 b'continuation flags set',
171 }) 171 })
172 172
173 def testneithernewnorcontinuation(self): 173 def testneithernewnorcontinuation(self):
174 result = self._sendsingleframe(makereactor(), 174 result = self._sendsingleframe(makereactor(),
175 ffs(b'1 1 stream-begin command-request 0 ')) 175 ffs(b'1 1 stream-begin command-request 0 '))
176 self.assertaction(result, 'error') 176 self.assertaction(result, b'error')
177 self.assertEqual(result[1], { 177 self.assertEqual(result[1], {
178 'message': b'received command request frame with neither new nor ' 178 b'message': b'received command request frame with neither new nor '
179 b'continuation flags set', 179 b'continuation flags set',
180 }) 180 })
181 181
182 def testunexpectedcommanddata(self): 182 def testunexpectedcommanddata(self):
183 """Command data frame when not running a command is an error.""" 183 """Command data frame when not running a command is an error."""
184 result = self._sendsingleframe(makereactor(), 184 result = self._sendsingleframe(makereactor(),
185 ffs(b'1 1 stream-begin command-data 0 ignored')) 185 ffs(b'1 1 stream-begin command-data 0 ignored'))
186 self.assertaction(result, 'error') 186 self.assertaction(result, b'error')
187 self.assertEqual(result[1], { 187 self.assertEqual(result[1], {
188 'message': b'expected command request frame; got 3', 188 b'message': b'expected command request frame; got 3',
189 }) 189 })
190 190
191 def testunexpectedcommanddatareceiving(self): 191 def testunexpectedcommanddatareceiving(self):
192 """Same as above except the command is receiving.""" 192 """Same as above except the command is receiving."""
193 results = list(sendframes(makereactor(), [ 193 results = list(sendframes(makereactor(), [
194 ffs(b'1 1 stream-begin command-request new|more ' 194 ffs(b'1 1 stream-begin command-request new|more '
195 b"cbor:{b'name': b'ignored'}"), 195 b"cbor:{b'name': b'ignored'}"),
196 ffs(b'1 1 0 command-data eos ignored'), 196 ffs(b'1 1 0 command-data eos ignored'),
197 ])) 197 ]))
198 198
199 self.assertaction(results[0], 'wantframe') 199 self.assertaction(results[0], b'wantframe')
200 self.assertaction(results[1], 'error') 200 self.assertaction(results[1], b'error')
201 self.assertEqual(results[1][1], { 201 self.assertEqual(results[1][1], {
202 'message': b'received command data frame for request that is not ' 202 b'message': b'received command data frame for request that is not '
203 b'expecting data: 1', 203 b'expecting data: 1',
204 }) 204 })
205 205
206 def testconflictingrequestidallowed(self): 206 def testconflictingrequestidallowed(self):
207 """Multiple fully serviced commands with same request ID is allowed.""" 207 """Multiple fully serviced commands with same request ID is allowed."""
208 reactor = makereactor() 208 reactor = makereactor()
210 outstream = reactor.makeoutputstream() 210 outstream = reactor.makeoutputstream()
211 results.append(self._sendsingleframe( 211 results.append(self._sendsingleframe(
212 reactor, ffs(b'1 1 stream-begin command-request new ' 212 reactor, ffs(b'1 1 stream-begin command-request new '
213 b"cbor:{b'name': b'command'}"))) 213 b"cbor:{b'name': b'command'}")))
214 result = reactor.onbytesresponseready(outstream, 1, b'response1') 214 result = reactor.onbytesresponseready(outstream, 1, b'response1')
215 self.assertaction(result, 'sendframes') 215 self.assertaction(result, b'sendframes')
216 list(result[1]['framegen']) 216 list(result[1][b'framegen'])
217 results.append(self._sendsingleframe( 217 results.append(self._sendsingleframe(
218 reactor, ffs(b'1 1 stream-begin command-request new ' 218 reactor, ffs(b'1 1 stream-begin command-request new '
219 b"cbor:{b'name': b'command'}"))) 219 b"cbor:{b'name': b'command'}")))
220 result = reactor.onbytesresponseready(outstream, 1, b'response2') 220 result = reactor.onbytesresponseready(outstream, 1, b'response2')
221 self.assertaction(result, 'sendframes') 221 self.assertaction(result, b'sendframes')
222 list(result[1]['framegen']) 222 list(result[1][b'framegen'])
223 results.append(self._sendsingleframe( 223 results.append(self._sendsingleframe(
224 reactor, ffs(b'1 1 stream-begin command-request new ' 224 reactor, ffs(b'1 1 stream-begin command-request new '
225 b"cbor:{b'name': b'command'}"))) 225 b"cbor:{b'name': b'command'}")))
226 result = reactor.onbytesresponseready(outstream, 1, b'response3') 226 result = reactor.onbytesresponseready(outstream, 1, b'response3')
227 self.assertaction(result, 'sendframes') 227 self.assertaction(result, b'sendframes')
228 list(result[1]['framegen']) 228 list(result[1][b'framegen'])
229 229
230 for i in range(3): 230 for i in range(3):
231 self.assertaction(results[i], 'runcommand') 231 self.assertaction(results[i], b'runcommand')
232 self.assertEqual(results[i][1], { 232 self.assertEqual(results[i][1], {
233 'requestid': 1, 233 b'requestid': 1,
234 'command': b'command', 234 b'command': b'command',
235 'args': {}, 235 b'args': {},
236 'data': None, 236 b'data': None,
237 }) 237 })
238 238
239 def testconflictingrequestid(self): 239 def testconflictingrequestid(self):
240 """Request ID for new command matching in-flight command is illegal.""" 240 """Request ID for new command matching in-flight command is illegal."""
241 results = list(sendframes(makereactor(), [ 241 results = list(sendframes(makereactor(), [
243 b"cbor:{b'name': b'command'}"), 243 b"cbor:{b'name': b'command'}"),
244 ffs(b'1 1 0 command-request new ' 244 ffs(b'1 1 0 command-request new '
245 b"cbor:{b'name': b'command1'}"), 245 b"cbor:{b'name': b'command1'}"),
246 ])) 246 ]))
247 247
248 self.assertaction(results[0], 'wantframe') 248 self.assertaction(results[0], b'wantframe')
249 self.assertaction(results[1], 'error') 249 self.assertaction(results[1], b'error')
250 self.assertEqual(results[1][1], { 250 self.assertEqual(results[1][1], {
251 'message': b'request with ID 1 already received', 251 b'message': b'request with ID 1 already received',
252 }) 252 })
253 253
254 def testinterleavedcommands(self): 254 def testinterleavedcommands(self):
255 cbor1 = cbor.dumps({ 255 cbor1 = cbor.dumps({
256 b'name': b'command1', 256 b'name': b'command1',
275 ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]), 275 ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]),
276 ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]), 276 ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]),
277 ])) 277 ]))
278 278
279 self.assertEqual([t[0] for t in results], [ 279 self.assertEqual([t[0] for t in results], [
280 'wantframe', 280 b'wantframe',
281 'wantframe', 281 b'wantframe',
282 'wantframe', 282 b'wantframe',
283 'wantframe', 283 b'wantframe',
284 'runcommand', 284 b'runcommand',
285 'runcommand', 285 b'runcommand',
286 ]) 286 ])
287 287
288 self.assertEqual(results[4][1], { 288 self.assertEqual(results[4][1], {
289 'requestid': 3, 289 b'requestid': 3,
290 'command': 'command3', 290 b'command': b'command3',
291 'args': {b'biz': b'baz', b'key': b'val'}, 291 b'args': {b'biz': b'baz', b'key': b'val'},
292 'data': None, 292 b'data': None,
293 }) 293 })
294 self.assertEqual(results[5][1], { 294 self.assertEqual(results[5][1], {
295 'requestid': 1, 295 b'requestid': 1,
296 'command': 'command1', 296 b'command': b'command1',
297 'args': {b'foo': b'bar', b'key1': b'val'}, 297 b'args': {b'foo': b'bar', b'key1': b'val'},
298 'data': None, 298 b'data': None,
299 }) 299 })
300 300
301 def testmissingcommanddataframe(self): 301 def testmissingcommanddataframe(self):
302 # The reactor doesn't currently handle partially received commands. 302 # The reactor doesn't currently handle partially received commands.
303 # So this test is failing to do anything with request 1. 303 # So this test is failing to do anything with request 1.
307 ffs(b'3 1 0 command-request new ' 307 ffs(b'3 1 0 command-request new '
308 b"cbor:{b'name': b'command2'}"), 308 b"cbor:{b'name': b'command2'}"),
309 ] 309 ]
310 results = list(sendframes(makereactor(), frames)) 310 results = list(sendframes(makereactor(), frames))
311 self.assertEqual(len(results), 2) 311 self.assertEqual(len(results), 2)
312 self.assertaction(results[0], 'wantframe') 312 self.assertaction(results[0], b'wantframe')
313 self.assertaction(results[1], 'runcommand') 313 self.assertaction(results[1], b'runcommand')
314 314
315 def testmissingcommanddataframeflags(self): 315 def testmissingcommanddataframeflags(self):
316 frames = [ 316 frames = [
317 ffs(b'1 1 stream-begin command-request new|have-data ' 317 ffs(b'1 1 stream-begin command-request new|have-data '
318 b"cbor:{b'name': b'command1'}"), 318 b"cbor:{b'name': b'command1'}"),
319 ffs(b'1 1 0 command-data 0 data'), 319 ffs(b'1 1 0 command-data 0 data'),
320 ] 320 ]
321 results = list(sendframes(makereactor(), frames)) 321 results = list(sendframes(makereactor(), frames))
322 self.assertEqual(len(results), 2) 322 self.assertEqual(len(results), 2)
323 self.assertaction(results[0], 'wantframe') 323 self.assertaction(results[0], b'wantframe')
324 self.assertaction(results[1], 'error') 324 self.assertaction(results[1], b'error')
325 self.assertEqual(results[1][1], { 325 self.assertEqual(results[1][1], {
326 'message': b'command data frame without flags', 326 b'message': b'command data frame without flags',
327 }) 327 })
328 328
329 def testframefornonreceivingrequest(self): 329 def testframefornonreceivingrequest(self):
330 """Receiving a frame for a command that is not receiving is illegal.""" 330 """Receiving a frame for a command that is not receiving is illegal."""
331 results = list(sendframes(makereactor(), [ 331 results = list(sendframes(makereactor(), [
333 b"cbor:{b'name': b'command1'}"), 333 b"cbor:{b'name': b'command1'}"),
334 ffs(b'3 1 0 command-request new|have-data ' 334 ffs(b'3 1 0 command-request new|have-data '
335 b"cbor:{b'name': b'command3'}"), 335 b"cbor:{b'name': b'command3'}"),
336 ffs(b'5 1 0 command-data eos ignored'), 336 ffs(b'5 1 0 command-data eos ignored'),
337 ])) 337 ]))
338 self.assertaction(results[2], 'error') 338 self.assertaction(results[2], b'error')
339 self.assertEqual(results[2][1], { 339 self.assertEqual(results[2][1], {
340 'message': b'received frame for request that is not receiving: 5', 340 b'message': b'received frame for request that is not receiving: 5',
341 }) 341 })
342 342
343 def testsimpleresponse(self): 343 def testsimpleresponse(self):
344 """Bytes response to command sends result frames.""" 344 """Bytes response to command sends result frames."""
345 reactor = makereactor() 345 reactor = makereactor()
346 instream = framing.stream(1) 346 instream = framing.stream(1)
347 list(sendcommandframes(reactor, instream, 1, b'mycommand', {})) 347 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
348 348
349 outstream = reactor.makeoutputstream() 349 outstream = reactor.makeoutputstream()
350 result = reactor.onbytesresponseready(outstream, 1, b'response') 350 result = reactor.onbytesresponseready(outstream, 1, b'response')
351 self.assertaction(result, 'sendframes') 351 self.assertaction(result, b'sendframes')
352 self.assertframesequal(result[1]['framegen'], [ 352 self.assertframesequal(result[1][b'framegen'], [
353 b'1 2 stream-begin bytes-response eos response', 353 b'1 2 stream-begin bytes-response eos response',
354 ]) 354 ])
355 355
356 def testmultiframeresponse(self): 356 def testmultiframeresponse(self):
357 """Bytes response spanning multiple frames is handled.""" 357 """Bytes response spanning multiple frames is handled."""
362 instream = framing.stream(1) 362 instream = framing.stream(1)
363 list(sendcommandframes(reactor, instream, 1, b'mycommand', {})) 363 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
364 364
365 outstream = reactor.makeoutputstream() 365 outstream = reactor.makeoutputstream()
366 result = reactor.onbytesresponseready(outstream, 1, first + second) 366 result = reactor.onbytesresponseready(outstream, 1, first + second)
367 self.assertaction(result, 'sendframes') 367 self.assertaction(result, b'sendframes')
368 self.assertframesequal(result[1]['framegen'], [ 368 self.assertframesequal(result[1][b'framegen'], [
369 b'1 2 stream-begin bytes-response continuation %s' % first, 369 b'1 2 stream-begin bytes-response continuation %s' % first,
370 b'1 2 0 bytes-response eos %s' % second, 370 b'1 2 0 bytes-response eos %s' % second,
371 ]) 371 ])
372 372
373 def testapplicationerror(self): 373 def testapplicationerror(self):
375 instream = framing.stream(1) 375 instream = framing.stream(1)
376 list(sendcommandframes(reactor, instream, 1, b'mycommand', {})) 376 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
377 377
378 outstream = reactor.makeoutputstream() 378 outstream = reactor.makeoutputstream()
379 result = reactor.onapplicationerror(outstream, 1, b'some message') 379 result = reactor.onapplicationerror(outstream, 1, b'some message')
380 self.assertaction(result, 'sendframes') 380 self.assertaction(result, b'sendframes')
381 self.assertframesequal(result[1]['framegen'], [ 381 self.assertframesequal(result[1][b'framegen'], [
382 b'1 2 stream-begin error-response application some message', 382 b'1 2 stream-begin error-response application some message',
383 ]) 383 ])
384 384
385 def test1commanddeferresponse(self): 385 def test1commanddeferresponse(self):
386 """Responses when in deferred output mode are delayed until EOF.""" 386 """Responses when in deferred output mode are delayed until EOF."""
387 reactor = makereactor(deferoutput=True) 387 reactor = makereactor(deferoutput=True)
388 instream = framing.stream(1) 388 instream = framing.stream(1)
389 results = list(sendcommandframes(reactor, instream, 1, b'mycommand', 389 results = list(sendcommandframes(reactor, instream, 1, b'mycommand',
390 {})) 390 {}))
391 self.assertEqual(len(results), 1) 391 self.assertEqual(len(results), 1)
392 self.assertaction(results[0], 'runcommand') 392 self.assertaction(results[0], b'runcommand')
393 393
394 outstream = reactor.makeoutputstream() 394 outstream = reactor.makeoutputstream()
395 result = reactor.onbytesresponseready(outstream, 1, b'response') 395 result = reactor.onbytesresponseready(outstream, 1, b'response')
396 self.assertaction(result, 'noop') 396 self.assertaction(result, b'noop')
397 result = reactor.oninputeof() 397 result = reactor.oninputeof()
398 self.assertaction(result, 'sendframes') 398 self.assertaction(result, b'sendframes')
399 self.assertframesequal(result[1]['framegen'], [ 399 self.assertframesequal(result[1][b'framegen'], [
400 b'1 2 stream-begin bytes-response eos response', 400 b'1 2 stream-begin bytes-response eos response',
401 ]) 401 ])
402 402
403 def testmultiplecommanddeferresponse(self): 403 def testmultiplecommanddeferresponse(self):
404 reactor = makereactor(deferoutput=True) 404 reactor = makereactor(deferoutput=True)
406 list(sendcommandframes(reactor, instream, 1, b'command1', {})) 406 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
407 list(sendcommandframes(reactor, instream, 3, b'command2', {})) 407 list(sendcommandframes(reactor, instream, 3, b'command2', {}))
408 408
409 outstream = reactor.makeoutputstream() 409 outstream = reactor.makeoutputstream()
410 result = reactor.onbytesresponseready(outstream, 1, b'response1') 410 result = reactor.onbytesresponseready(outstream, 1, b'response1')
411 self.assertaction(result, 'noop') 411 self.assertaction(result, b'noop')
412 result = reactor.onbytesresponseready(outstream, 3, b'response2') 412 result = reactor.onbytesresponseready(outstream, 3, b'response2')
413 self.assertaction(result, 'noop') 413 self.assertaction(result, b'noop')
414 result = reactor.oninputeof() 414 result = reactor.oninputeof()
415 self.assertaction(result, 'sendframes') 415 self.assertaction(result, b'sendframes')
416 self.assertframesequal(result[1]['framegen'], [ 416 self.assertframesequal(result[1][b'framegen'], [
417 b'1 2 stream-begin bytes-response eos response1', 417 b'1 2 stream-begin bytes-response eos response1',
418 b'3 2 0 bytes-response eos response2' 418 b'3 2 0 bytes-response eos response2'
419 ]) 419 ])
420 420
421 def testrequestidtracking(self): 421 def testrequestidtracking(self):
430 reactor.onbytesresponseready(outstream, 3, b'response3') 430 reactor.onbytesresponseready(outstream, 3, b'response3')
431 reactor.onbytesresponseready(outstream, 1, b'response1') 431 reactor.onbytesresponseready(outstream, 1, b'response1')
432 reactor.onbytesresponseready(outstream, 5, b'response5') 432 reactor.onbytesresponseready(outstream, 5, b'response5')
433 433
434 result = reactor.oninputeof() 434 result = reactor.oninputeof()
435 self.assertaction(result, 'sendframes') 435 self.assertaction(result, b'sendframes')
436 self.assertframesequal(result[1]['framegen'], [ 436 self.assertframesequal(result[1][b'framegen'], [
437 b'3 2 stream-begin bytes-response eos response3', 437 b'3 2 stream-begin bytes-response eos response3',
438 b'1 2 0 bytes-response eos response1', 438 b'1 2 0 bytes-response eos response1',
439 b'5 2 0 bytes-response eos response5', 439 b'5 2 0 bytes-response eos response5',
440 ]) 440 ])
441 441
444 reactor = makereactor() 444 reactor = makereactor()
445 stream = framing.stream(1) 445 stream = framing.stream(1)
446 list(sendcommandframes(reactor, stream, 1, b'command1', {})) 446 list(sendcommandframes(reactor, stream, 1, b'command1', {}))
447 results = list(sendcommandframes(reactor, stream, 1, b'command1', {})) 447 results = list(sendcommandframes(reactor, stream, 1, b'command1', {}))
448 448
449 self.assertaction(results[0], 'error') 449 self.assertaction(results[0], b'error')
450 self.assertEqual(results[0][1], { 450 self.assertEqual(results[0][1], {
451 'message': b'request with ID 1 is already active', 451 b'message': b'request with ID 1 is already active',
452 }) 452 })
453 453
454 def testduplicaterequestonactivecommandnosend(self): 454 def testduplicaterequestonactivecommandnosend(self):
455 """Same as above but we've registered a response but haven't sent it.""" 455 """Same as above but we've registered a response but haven't sent it."""
456 reactor = makereactor() 456 reactor = makereactor()
461 461
462 # We've registered the response but haven't sent it. From the 462 # We've registered the response but haven't sent it. From the
463 # perspective of the reactor, the command is still active. 463 # perspective of the reactor, the command is still active.
464 464
465 results = list(sendcommandframes(reactor, instream, 1, b'command1', {})) 465 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
466 self.assertaction(results[0], 'error') 466 self.assertaction(results[0], b'error')
467 self.assertEqual(results[0][1], { 467 self.assertEqual(results[0][1], {
468 'message': b'request with ID 1 is already active', 468 b'message': b'request with ID 1 is already active',
469 }) 469 })
470 470
471 def testduplicaterequestaftersend(self): 471 def testduplicaterequestaftersend(self):
472 """We can use a duplicate request ID after we've sent the response.""" 472 """We can use a duplicate request ID after we've sent the response."""
473 reactor = makereactor() 473 reactor = makereactor()
474 instream = framing.stream(1) 474 instream = framing.stream(1)
475 list(sendcommandframes(reactor, instream, 1, b'command1', {})) 475 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
476 outstream = reactor.makeoutputstream() 476 outstream = reactor.makeoutputstream()
477 res = reactor.onbytesresponseready(outstream, 1, b'response') 477 res = reactor.onbytesresponseready(outstream, 1, b'response')
478 list(res[1]['framegen']) 478 list(res[1][b'framegen'])
479 479
480 results = list(sendcommandframes(reactor, instream, 1, b'command1', {})) 480 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
481 self.assertaction(results[0], 'runcommand') 481 self.assertaction(results[0], b'runcommand')
482 482
483 if __name__ == '__main__': 483 if __name__ == '__main__':
484 import silenttestrunner 484 import silenttestrunner
485 silenttestrunner.main(__name__) 485 silenttestrunner.main(__name__)