Skip to content

Commit

Permalink
Merge pull request #219 from powerapi-ng/fix/issue218/correcting-beha…
Browse files Browse the repository at this point in the history
…vior-dispatcher-tests

Fix/issue218/correcting behavior dispatcher tests
  • Loading branch information
gfieni authored Dec 1, 2023
2 parents d6532f1 + 4ac8de4 commit 8db7494
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/powerapi/processor/pre/k8s/k8s_pre_processor_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from powerapi.processor.pre.k8s.k8s_pre_processor_handlers import K8sPreProcessorActorHWPCReportHandler, \
K8sPreProcessorActorStartMessageHandler, K8sPreProcessorActorPoisonPillMessageHandler
from powerapi.processor.processor_actor import ProcessorState, ProcessorActor
from powerapi.report import HWPCReport
from powerapi.report.report import Report

ADDED_EVENT = 'ADDED'
DELETED_EVENT = 'DELETED'
Expand Down Expand Up @@ -211,6 +211,6 @@ def setup(self):
"""
ProcessorActor.setup(self)
self.add_handler(message_type=StartMessage, handler=K8sPreProcessorActorStartMessageHandler(state=self.state))
self.add_handler(message_type=HWPCReport, handler=K8sPreProcessorActorHWPCReportHandler(state=self.state))
self.add_handler(message_type=Report, handler=K8sPreProcessorActorHWPCReportHandler(state=self.state))
self.add_handler(message_type=PoisonPillMessage,
handler=K8sPreProcessorActorPoisonPillMessageHandler(state=self.state))
4 changes: 3 additions & 1 deletion tests/unit/actor/abstract_test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ def init_actor(self, actor):
def started_actor(self, init_actor):
init_actor.send_control(StartMessage('test_case'))
_ = init_actor.receive_control(2000)
return init_actor
yield init_actor

init_actor.send_control(PoisonPillMessage())

@pytest.fixture
def started_fake_pusher_power_report(self, dummy_pipe_in):
Expand Down
21 changes: 9 additions & 12 deletions tests/unit/dispatcher/test_dispatcher_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,23 @@ def test_send_Report1_without_dispatch_rule_for_Report1_dont_create_formula(self
@define_dispatch_rules([(Report1, DispatchRule1AB(primary=True))])
def test_send_Report1_with_dispatch_rule_for_Report1_and_no_formula_created_must_create_a_new_formula(self,
started_actor,
dummy_pipe_out,
shutdown_system):
dummy_pipe_out):

"""
Check that a formula is created when a report is received
"""
started_actor.send_data(REPORT_1)
_, power_report = recv_from_pipe(dummy_pipe_out, 2)
_, power_report = recv_from_pipe(dummy_pipe_out, 0.2)
assert isinstance(power_report, PowerReport)
assert power_report.power == 42

# started_actor.send_control(PoisonPillMessage())

@pytest.mark.usefixtures("shutdown_system")
@define_dispatch_rules([(Report1, DispatchRule1AB(primary=True))])
def test_send_Report1_with_dispatch_rule_for_Report1_and_one_formula_send_report_to_formula(self,
dispatcher_with_formula,
dummy_pipe_out,
shutdown_system):
dummy_pipe_out):
"""
Check that DispatcherActor with a created formula sent a report to it
"""
Expand All @@ -367,8 +367,7 @@ def test_send_Report1_with_dispatch_rule_for_Report1_and_one_formula_send_report
(Report2, DispatchRule2A())])
def test_send_Report2_with_dispatch_rule_for_Report1_Primary_and_two_formula_send_report_to_all_formula(self,
dispatcher_with_two_formula,
dummy_pipe_out,
shutdown_system):
dummy_pipe_out):

"""
Check that DispatcherActor sent a report to all existing formulas
Expand All @@ -394,7 +393,7 @@ def test_send_Report2_with_dispatch_rule_for_Report1_Primary_and_two_formula_sen

@define_dispatch_rules([(Report1, DispatchRule1AB(primary=True))])
def test_send_REPORT1_B2_with_dispatch_rule_1AB_must_create_two_formula(self, started_actor,
dummy_pipe_out, shutdown_system):
dummy_pipe_out):
"""
Check that two formulas are created by DispatcherActor
"""
Expand All @@ -411,8 +410,7 @@ def test_send_REPORT1_B2_with_dispatch_rule_1AB_must_create_two_formula(self, st
(Report3, DispatchRule3())])
def test_send_REPORT3_on_dispatcher_with_two_formula_and_dispatch_rule_1AB_send_report_to_one_formula(self,
dispatcher_with_two_formula,
dummy_pipe_out,
shutdown_system):
dummy_pipe_out):

"""
Check that 3 reports are produced by formulas when DispatcherActor receives
Expand All @@ -431,8 +429,7 @@ def test_send_REPORT3_on_dispatcher_with_two_formula_and_dispatch_rule_1AB_send_
assert recv_from_pipe(dummy_pipe_out, 0.5) == (None, None)

@define_dispatch_rules([(Report1, DispatchRule1AB(primary=True))])
def test_send_PoisonPillMessage_make_dispatcher_forward_it_to_formula(self, dispatcher_with_two_formula,
shutdown_system):
def test_send_PoisonPillMessage_make_dispatcher_forward_it_to_formula(self, dispatcher_with_two_formula):
"""
Check that a PoissonPillMessage stops the DispatcherActor as well as their formulas
"""
Expand Down

0 comments on commit 8db7494

Please sign in to comment.