def test_read_multiple_messages(self):
    test_bytes = b'Content-Length: 30\r\n\r\n{"method":"test", "params":{}}'
    input_stream = io.BytesIO((test_bytes + test_bytes))
    output_stream = io.BytesIO()
    server = JSONRPCServer(input_stream, output_stream, logger=utils.get_mock_logger())
    dispatch_mock = mock.MagicMock()
    server._dispatch_message = dispatch_mock
    server.start()
    time.sleep(1)
    server.stop()
    server.wait_for_exit()
    expected_output = JSONRPCMessage.from_dictionary({'method': 'test', 'params': {}})
    self.assertEqual(len(dispatch_mock.mock_calls), 2)
    self.assertDictEqual(dispatch_mock.mock_calls[0][1][0].dictionary, expected_output.dictionary)
    self.assertDictEqual(dispatch_mock.mock_calls[1][1][0].dictionary, expected_output.dictionary)
    self.assertFalse(server._input_consumer.isAlive())
    self.assertFalse(server._output_consumer.isAlive())
def test_read_multiple_messages(self):
    test_bytes = b'Content-Length: 30\r\n\r\n{"method":"test", "params":{}}'
    input_stream = io.BytesIO((test_bytes + test_bytes))
    output_stream = io.BytesIO()
    server = JSONRPCServer(input_stream, output_stream, logger=utils.get_mock_logger())
    dispatch_mock = mock.MagicMock()
    server._dispatch_message = dispatch_mock
    server.start()
    time.sleep(1)
    server.stop()
    server.wait_for_exit()
    expected_output = JSONRPCMessage.from_dictionary({'method': 'test', 'params': {}})
    self.assertEqual(len(dispatch_mock.mock_calls), 2)
    self.assertDictEqual(dispatch_mock.mock_calls[0][1][0].dictionary, expected_output.dictionary)
    self.assertDictEqual(dispatch_mock.mock_calls[1][1][0].dictionary, expected_output.dictionary)
    self.assertFalse(server._input_consumer.isAlive())
    self.assertFalse(server._output_consumer.isAlive())