def testRegisterClient(self, *_):
     my_app = app.App()
     with self.assertRaises(Exception):
         my_app.get_client_class()
     my_client = mock.Mock()
     my_app.register_client(my_client)
     self.assertEqual(my_app.get_client_class(), my_client)
コード例 #2
0
 def testSchedSetAffinity(self):
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         pinned_cpus={1, 2, 3},
         iterations=0,
     )
     self.sched_setaffinity_mock.assert_called_once_with(0, {1, 2, 3})
 def testRegisterRunner(self, benchmark_scenario_flag, *_):
     foo_runner = mock.Mock()
     bar_runner = mock.Mock()
     my_app = app.App()
     my_app._register_runner('foo', foo_runner)
     my_app._register_runner('bar', bar_runner)
     benchmark_scenario_flag.value = 'foo'
     self.assertEqual(my_app.get_runner_class(), foo_runner)
     benchmark_scenario_flag.value = 'bar'
     self.assertEqual(my_app.get_runner_class(), bar_runner)
     benchmark_scenario_flag.value = 'baz'
     with self.assertRaises(Exception):
         my_app.get_runner_class()
コード例 #4
0
 def testInitialization(self):
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         iterations=0,
     )
     self.sched_setaffinity_mock.assert_not_called()
     self.flags_mock.assert_called_once_with(['--foo=bar', '--bar=qux'],
                                             known_only=True)
     self.get_client_class_mock().from_flags.assert_called_once_with()
     self.communicator_mock.assert_called_once_with(self.input_conn_mock,
                                                    self.output_conn_mock)
     self.communicator_instance_mock.greet.assert_called_once_with()
コード例 #5
0
 def testMainLoop(self):
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         iterations=1,
     )
     self.parent_mock.assert_has_calls([
         mock.call.communicator.greet(),
         mock.call.communicator.await_from_main(protocol.Publish),
         mock.call.client.generate_random_message(
             self.flags_mock.message_size),
         mock.call.client.publish_message(mock.ANY),
         mock.call.communicator.send(
             protocol.AckPublish(publish_timestamp=self._curr_timens)),
     ])
コード例 #6
0
 def testMainLoopError(self):
     error = Exception('Too bad')
     self.client_instance_mock.pull_message.side_effect = error
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         iterations=1,
     )
     self.parent_mock.assert_has_calls([
         mock.call.communicator.greet(),
         mock.call.communicator.await_from_main(protocol.Consume,
                                                protocol.AckConsume()),
         mock.call.client.pull_message(),
         mock.call.communicator.send(
             protocol.ReceptionReport(receive_error=repr(error))),
     ])
コード例 #7
0
 def testMainLoopError(self):
     error = Exception('Too bad')
     self.client_instance_mock.publish_message.side_effect = error
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         iterations=1,
     )
     self.parent_mock.assert_has_calls([
         mock.call.communicator.greet(),
         mock.call.communicator.await_from_main(protocol.Publish),
         mock.call.client.generate_random_message(
             self.flags_mock.message_size),
         mock.call.client.publish_message(mock.ANY),
         mock.call.communicator.send(
             protocol.AckPublish(publish_error=repr(error))),
     ])
コード例 #8
0
 def testMainLoop(self):
     self.Main(
         input_conn=self.input_conn_mock,
         output_conn=self.output_conn_mock,
         serialized_flags='--foo=bar\n--bar=qux',
         app=app.App(),
         iterations=1,
     )
     reception_report = self.communicator_instance_mock.send.call_args[0][0]
     pull_timestamp = reception_report.receive_timestamp
     ack_timestamp = reception_report.ack_timestamp
     self.assertEqual(ack_timestamp - pull_timestamp, 1_000_000_000)
     self.parent_mock.assert_has_calls([
         mock.call.communicator.greet(),
         mock.call.communicator.await_from_main(protocol.Consume,
                                                protocol.AckConsume()),
         mock.call.client.pull_message(),
         mock.call.client.acknowledge_received_message(mock.ANY),
         mock.call.communicator.send(
             protocol.ReceptionReport(receive_timestamp=pull_timestamp,
                                      ack_timestamp=ack_timestamp)),
     ])