172 self.assertEqual(val, [ |
172 self.assertEqual(val, [ |
173 ffs(br'1 text-output 0 \x06\x00\x01\x01\x05\x03\x00foo %slabelarg'), |
173 ffs(br'1 text-output 0 \x06\x00\x01\x01\x05\x03\x00foo %slabelarg'), |
174 ]) |
174 ]) |
175 |
175 |
176 class ServerReactorTests(unittest.TestCase): |
176 class ServerReactorTests(unittest.TestCase): |
177 def _sendsingleframe(self, reactor, s): |
177 def _sendsingleframe(self, reactor, f): |
178 results = list(sendframes(reactor, [ffs(s)])) |
178 results = list(sendframes(reactor, [f])) |
179 self.assertEqual(len(results), 1) |
179 self.assertEqual(len(results), 1) |
180 |
180 |
181 return results[0] |
181 return results[0] |
182 |
182 |
183 def assertaction(self, res, expected): |
183 def assertaction(self, res, expected): |
294 }) |
294 }) |
295 |
295 |
296 def testunexpectedcommandargument(self): |
296 def testunexpectedcommandargument(self): |
297 """Command argument frame when not running a command is an error.""" |
297 """Command argument frame when not running a command is an error.""" |
298 result = self._sendsingleframe(makereactor(), |
298 result = self._sendsingleframe(makereactor(), |
299 b'1 command-argument 0 ignored') |
299 ffs(b'1 command-argument 0 ignored')) |
300 self.assertaction(result, 'error') |
300 self.assertaction(result, 'error') |
301 self.assertEqual(result[1], { |
301 self.assertEqual(result[1], { |
302 'message': b'expected command frame; got 2', |
302 'message': b'expected command frame; got 2', |
303 }) |
303 }) |
304 |
304 |
316 }) |
316 }) |
317 |
317 |
318 def testunexpectedcommanddata(self): |
318 def testunexpectedcommanddata(self): |
319 """Command argument frame when not running a command is an error.""" |
319 """Command argument frame when not running a command is an error.""" |
320 result = self._sendsingleframe(makereactor(), |
320 result = self._sendsingleframe(makereactor(), |
321 b'1 command-data 0 ignored') |
321 ffs(b'1 command-data 0 ignored')) |
322 self.assertaction(result, 'error') |
322 self.assertaction(result, 'error') |
323 self.assertEqual(result[1], { |
323 self.assertEqual(result[1], { |
324 'message': b'expected command frame; got 3', |
324 'message': b'expected command frame; got 3', |
325 }) |
325 }) |
326 |
326 |
338 }) |
338 }) |
339 |
339 |
340 def testmissingcommandframeflags(self): |
340 def testmissingcommandframeflags(self): |
341 """Command name frame must have flags set.""" |
341 """Command name frame must have flags set.""" |
342 result = self._sendsingleframe(makereactor(), |
342 result = self._sendsingleframe(makereactor(), |
343 b'1 command-name 0 command') |
343 ffs(b'1 command-name 0 command')) |
344 self.assertaction(result, 'error') |
344 self.assertaction(result, 'error') |
345 self.assertEqual(result[1], { |
345 self.assertEqual(result[1], { |
346 'message': b'missing frame flags on command frame', |
346 'message': b'missing frame flags on command frame', |
347 }) |
347 }) |
348 |
348 |
349 def testconflictingrequestid(self): |
349 def testconflictingrequestidallowed(self): |
350 """Multiple fully serviced commands with same request ID is allowed.""" |
350 """Multiple fully serviced commands with same request ID is allowed.""" |
351 results = list(sendframes(makereactor(), [ |
351 reactor = makereactor() |
352 ffs(b'1 command-name eos command'), |
352 results = [] |
353 ffs(b'1 command-name eos command'), |
353 results.append(self._sendsingleframe( |
354 ffs(b'1 command-name eos command'), |
354 reactor, ffs(b'1 command-name eos command'))) |
355 ])) |
355 result = reactor.onbytesresponseready(1, b'response1') |
|
356 self.assertaction(result, 'sendframes') |
|
357 list(result[1]['framegen']) |
|
358 results.append(self._sendsingleframe( |
|
359 reactor, ffs(b'1 command-name eos command'))) |
|
360 result = reactor.onbytesresponseready(1, b'response2') |
|
361 self.assertaction(result, 'sendframes') |
|
362 list(result[1]['framegen']) |
|
363 results.append(self._sendsingleframe( |
|
364 reactor, ffs(b'1 command-name eos command'))) |
|
365 result = reactor.onbytesresponseready(1, b'response3') |
|
366 self.assertaction(result, 'sendframes') |
|
367 list(result[1]['framegen']) |
|
368 |
356 for i in range(3): |
369 for i in range(3): |
357 self.assertaction(results[i], 'runcommand') |
370 self.assertaction(results[i], 'runcommand') |
358 self.assertEqual(results[i][1], { |
371 self.assertEqual(results[i][1], { |
359 'requestid': 1, |
372 'requestid': 1, |
360 'command': b'command', |
373 'command': b'command', |