def test_send_two_report_to_a_dispatcher_with_crashed_formula_must_restart_formula(self, system, dispatcher_with_formula, dummy_pipe_out): # make formula crash system.tell(dispatcher_with_formula, REPORT_1) b, a = recv_from_pipe(dummy_pipe_out, 0.5) system.tell(dispatcher_with_formula, REPORT_1) _, msg = recv_from_pipe(dummy_pipe_out, 0.5) assert msg == 'crash' # send two report system.tell(dispatcher_with_formula, REPORT_1) _, msg = recv_from_pipe(dummy_pipe_out, 0.5) assert msg == 'crash' system.tell(dispatcher_with_formula, REPORT_1) _, msg = recv_from_pipe(dummy_pipe_out, 0.5) assert msg == 'crash' # test if formula restart def check_if_restart(): for i in range(100): system.tell(dispatcher_with_formula, REPORT_1) _, start_msg = recv_from_pipe(dummy_pipe_out, 0.5) if isinstance(start_msg, StartMessage): return True return False assert check_if_restart() # test if next message is forwarded system.tell(dispatcher_with_formula, REPORT_1) _, msg1 = recv_from_pipe(dummy_pipe_out, 0.5) assert msg1 == REPORT_1
def test_send_ActorExitRequest_make_dispatcher_forward_it_to_formula(self, system, dispatcher_with_two_formula, logger, dummy_pipe_out): system.tell(dispatcher_with_two_formula, ActorExitRequest()) _, msg1 = recv_from_pipe(dummy_pipe_out, 0.5) _, msg2 = recv_from_pipe(dummy_pipe_out, 0.5) assert msg1 == 'dead' assert msg2 == 'dead'
def test_send_Report2_with_dispatch_rule_for_Report1_Primary_and_two_formula_forward_report_to_all_formula(self, system, dispatcher_with_two_formula, dummy_pipe_out): system.tell(dispatcher_with_two_formula, REPORT_2) _, msg1 = recv_from_pipe(dummy_pipe_out, 0.5) _, msg2 = recv_from_pipe(dummy_pipe_out, 0.5) assert msg1 == REPORT_2 assert msg2 == REPORT_2 assert recv_from_pipe(dummy_pipe_out, 0.5) == (None,None)
def test_send_REPORT3_on_dispatcher_with_two_formula_and_dispatch_rule_1AB_send_report_to_one_formula(self, system, started_actor, dummy_pipe_out): system.tell(started_actor, REPORT_1_B2) start_message = [] reports = [] for _ in range(4): _, msg = recv_from_pipe(dummy_pipe_out, 0.5) system.tell(started_actor, REPORT_3) _, msg = recv_from_pipe(dummy_pipe_out, 0.5) assert msg == REPORT_3 assert recv_from_pipe(dummy_pipe_out, 0.5) == (None,None)
def test_send_Report_to_dummy_formula_make_formula_send_power_report_to_logger_with_42_as_power_value_after_1_second(self, system, started_actor, dummy_pipe_out): report1 = Report(1, 2, 3) system.tell(started_actor, report1) _, msg = recv_from_pipe(dummy_pipe_out, 2) assert isinstance(msg, PowerReport) assert msg.power == 42
def test_send_hwpc_report_to_rapl_formula_return_correct_result( self, system, started_actor, dummy_pipe_out): report = HWPCReport.from_json({ "timestamp": "2021-10-05T09:14:58.226", "sensor": "toto", "target": "all", "groups": { "rapl": { "0": { "7": { "RAPL_ENERGY_PKG": 5558763520.0, "time_enabled": 1000770053.0, "time_running": 1000770053.0 } } } } }) system.tell(started_actor, report) _, msg = recv_from_pipe(dummy_pipe_out, 1) assert isinstance(msg, PowerReport) assert msg.power == math.ldexp(5558763520.0, -32)
def check_if_restart(): for i in range(100): system.tell(dispatcher_with_formula, REPORT_1) _, start_msg = recv_from_pipe(dummy_pipe_out, 0.5) if isinstance(start_msg, StartMessage): return True return False
def test_send_5_message_to_dispatcher_that_handle_DummyFormula_send_5_PowerReport_to_FakePusher( system, started_dispatcher, dummy_pipe_out): for report in gen_HWPCReports(5): system.tell(started_dispatcher, report) for _ in range(5): _, msg = recv_from_pipe(dummy_pipe_out, 1) assert isinstance(msg, PowerReport)
def test_dispatcher_that_start_formula_crashing_at_initialization_musnt_forward_report_to_this_formula(self, system, dispatch_rules, actor, logger, dummy_pipe_out): route_table = RouteTable() for report_type, gbr in dispatch_rules: route_table.dispatch_rule(report_type, gbr) values = FormulaValues({'fake_pusher': LOGGER_NAME}) start_message = DispatcherStartMessage('system', 'dispatcher', CrashInitFormulaActor, values, route_table, 'test_device') system.ask(actor, start_message) system.tell(actor, REPORT_1) assert recv_from_pipe(dummy_pipe_out, 0.5) == (None,None)
def test_send_REPORT1_B2_with_dispatch_rule_1AB_must_create_two_formula(self, system, started_actor, dummy_pipe_out): system.tell(started_actor, REPORT_1_B2) start_message = [] reports = [] for _ in range(4): _, msg = recv_from_pipe(dummy_pipe_out, 0.5) if isinstance(msg, StartMessage): start_message.append(msg) if isinstance(msg, Report): reports.append(msg) assert len(reports) == 2 assert len(start_message) == 2 for msg in start_message: assert msg.name == 'formula0__a__b' or msg.name == 'formula1__a__b2'
def test_send_one_power_report_to_pusher_make_it_save_to_database( self, system, started_actor, pipe_out): system.tell(started_actor, POWER_REPORT_1) assert recv_from_pipe(pipe_out, 0.5) == POWER_REPORT_1
def test_send_EndMessage_to_dispatcher_with_two_formula_must_forward_it_to_all_formula(self, system, dispatcher_with_two_formula, dummy_pipe_out): system.tell(dispatcher_with_two_formula, EndMessage('system')) end_messages = 0 for _ in range(2): _, msg = recv_from_pipe(dummy_pipe_out, 2) assert isinstance(msg, EndMessage)
def dispatcher_with_two_formula(self, system, dispatcher_with_formula, logger, dispatch_rules, dummy_pipe_out): system.tell(dispatcher_with_formula, Report1('a', 'c')) recv_from_pipe(dummy_pipe_out, 0.5) recv_from_pipe(dummy_pipe_out, 0.5) return dispatcher_with_formula
def test_start_actor_with_db_that_contains_2_report_make_actor_send_reports_to_dispatcher( self, system, started_actor, fake_dispatcher, content, dummy_pipe_out): for report in content: assert recv_from_pipe(dummy_pipe_out, 2) == ('dispatcher', report)
def test_send_Report1_with_dispatch_rule_for_Report1_and_one_formula_forward_report_to_formula(self, system, dispatcher_with_formula, logger, dummy_pipe_out): system.tell(dispatcher_with_formula, REPORT_1) _, msg = recv_from_pipe(dummy_pipe_out, 0.5) assert msg == REPORT_1 assert recv_from_pipe(dummy_pipe_out, 0.5) == (None,None)
def test_send_Report1_with_dispatch_rule_for_Report1_and_no_formula_created_must_create_a_new_formula(self, system, started_actor, dummy_pipe_out): system.tell(started_actor, REPORT_1) _, start_msg = recv_from_pipe(dummy_pipe_out, 0.5) assert isinstance(start_msg, StartMessage) assert start_msg.name == 'formula0__a__b'
def test_send_Report1_without_dispatch_rule_for_Report1_dont_create_formula(self, system, started_actor, logger, dummy_pipe_out): system.tell(started_actor, REPORT_1) assert recv_from_pipe(dummy_pipe_out, 0.5) == (None,None)
def test_starting_actor_in_non_stream_mode_make_it_send_EndMessage_to_dispatcher( self, system, started_actor, fake_filter, dummy_pipe_out): _, msg = recv_from_pipe(dummy_pipe_out, 2) assert isinstance(msg, EndMessage)
def dispatcher_with_formula(self, system, started_actor, logger, dispatch_rules, dummy_pipe_out): system.tell(started_actor, REPORT_1) recv_from_pipe(dummy_pipe_out, 0.5) recv_from_pipe(dummy_pipe_out, 0.5) return started_actor