コード例 #1
0
 async def testStartStop(self, read_subprocess_output_mock,
                         join_subprocess_mock):
     worker = main_process.PublisherWorker()
     self.assertEqual(self.pipe_mock.call_count, 2)
     self.assertEqual(
         self._GetSubprocessInWriter(worker)._extract_mock_name(),
         'pipe_writer')
     self.assertEqual(
         self._GetSubprocessInReader(worker)._extract_mock_name(),
         'pipe_reader')
     self.assertEqual(
         self._GetSubprocessOutWriter(worker)._extract_mock_name(),
         'pipe_writer')
     self.assertEqual(
         self._GetSubprocessOutReader(worker)._extract_mock_name(),
         'pipe_reader')
     self.assertEqual(worker.subprocess_func, publisher.main)
     await worker.start()
     self.process_mock.assert_called_once_with(
         target=publisher.main,
         kwargs={
             'input_conn': worker.subprocess_in_reader,
             'output_conn': worker.subprocess_out_writer,
             'serialized_flags': self.flags_mock.flags_into_string(),
             'app': self.app_mock.get_instance.return_value,
             'pinned_cpus': None,
         })
     read_subprocess_output_mock.assert_called_once_with(
         protocol.Ready, None)
     await worker.stop()
     self.subprocess_mock.terminate.assert_called_once_with()
     join_subprocess_mock.assert_called_once_with(None)
コード例 #2
0
 async def testPublish(self, read_subprocess_output_mock, *_):
     worker = main_process.PublisherWorker()
     await worker.start()
     self.assertEqual(await worker.publish(), 1000)
     self._GetSubprocessInWriter(worker).send.assert_called_once_with(
         protocol.Publish())
     read_subprocess_output_mock.assert_called_once_with(
         protocol.AckPublish, None)
     await worker.stop()
コード例 #3
0
 async def testReadSubprocessOutputTimeout(self, _):
     worker = main_process.PublisherWorker()
     with mock.patch.object(main_process.BaseWorker,
                            '_read_subprocess_output',
                            return_value=Just()):
         await worker.start()
     worker.subprocess_out_reader.poll.side_effect = itertools.repeat(False)
     self._GetSubprocessOutReader(worker).recv.assert_not_called()
     with self.assertRaises(errors.EndToEnd.SubprocessTimeoutError):
         await worker._read_subprocess_output(str, 0.2)
     await worker.stop()
コード例 #4
0
 async def testStopKill(self, read_subprocess_output_mock,
                        join_subprocess_mock):
     worker = main_process.PublisherWorker()
     await worker.start()
     read_subprocess_output_mock.assert_called_once_with(
         protocol.Ready, None)
     await worker.stop()
     self.subprocess_mock.terminate.assert_called_once_with()
     self.subprocess_mock.kill.assert_called_once_with()
     join_subprocess_mock.assert_has_calls(
         [mock.call(None), mock.call(None)])
コード例 #5
0
 async def testReadSubprocessUnexpectedObject(self, _):
     worker = main_process.PublisherWorker()
     with mock.patch.object(main_process.BaseWorker,
                            '_read_subprocess_output',
                            return_value=Just()):
         await worker.start()
     worker.subprocess_out_reader.poll.return_value = True
     worker.subprocess_out_reader.recv.return_value = 42
     with self.assertRaises(errors.EndToEnd.ReceivedUnexpectedObjectError):
         await worker._read_subprocess_output(str)
     self._GetSubprocessOutReader(worker).recv.assert_called_once_with()
     await worker.stop()
コード例 #6
0
 async def testReadSubprocessOutput(self, _, sleep_mock):
     worker = main_process.PublisherWorker()
     with mock.patch.object(main_process.BaseWorker,
                            '_read_subprocess_output',
                            return_value=Just()):
         await worker.start()
     worker.subprocess_out_reader.poll.side_effect = [False, True]
     worker.subprocess_out_reader.recv.return_value = 'hola'
     self.assertEqual(await worker._read_subprocess_output(str), 'hola')
     sleep_mock.assert_called_once_with(worker.SLEEP_TIME)
     self.assertEqual(
         self._GetSubprocessOutReader(worker).poll.call_count, 2)
     self._GetSubprocessOutReader(worker).recv.assert_called_once_with()
     await worker.stop()
コード例 #7
0
    async def _async_run_phase(self, number_of_messages: int, _: int):
        """Actual coroutine implementing run phase logic."""

        publisher = main_process.PublisherWorker(self.PUBLISHER_PINNED_CPUS)
        receiver = main_process.ReceiverWorker(self.RECEIVER_PINNED_CPUS)
        e2e_pull_latencies = []
        e2e_ack_latencies = []
        failure_counter = 0

        try:
            await asyncio.wait([publisher.start(), receiver.start()])
            for _ in range(number_of_messages):
                try:
                    await receiver.start_consumption()
                    # Give time for the receiver to actually start pulling.
                    # RECEIVER_PULL_TIME_MARGIN should be big enough for the receiver to
                    # have started pulling after being commanded to do so, while small
                    # enough to make this test run on a reasonable time.
                    await asyncio.sleep(RECEIVER_PULL_TIME_MARGIN)
                    publish_timestamp = await publisher.publish()
                    receive_timestamp, ack_timestamp = await receiver.receive()
                    e2e_pull_latencies.append(
                        nanoseconds_to_milliseconds(receive_timestamp -
                                                    publish_timestamp))
                    e2e_ack_latencies.append(
                        nanoseconds_to_milliseconds(ack_timestamp -
                                                    publish_timestamp))
                except errors.EndToEnd.SubprocessFailedOperationError:
                    failure_counter += 1
        except Exception:  # pylint: disable=broad-except
            failure_counter += number_of_messages - len(e2e_pull_latencies)
        finally:
            await asyncio.wait([publisher.stop(), receiver.stop()])

        # getting summary statistics
        pull_metrics = self._get_summary_statistics('e2e_latency',
                                                    e2e_pull_latencies,
                                                    number_of_messages,
                                                    failure_counter)
        acknowledge_metrics = self._get_summary_statistics(
            'e2e_acknowledge_latency', e2e_ack_latencies, number_of_messages,
            failure_counter)

        # merging metrics dictionaries
        metrics = {**pull_metrics, **acknowledge_metrics}

        print(json.dumps(metrics))
        return metrics
コード例 #8
0
 async def testPublishError(self, *_):
     worker = main_process.PublisherWorker()
     await worker.start()
     with self.assertRaises(errors.EndToEnd.SubprocessFailedOperationError):
         await worker.publish()
     await worker.stop()