Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue218/correcting behavior dispatcher tests #219

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"""
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))

Check warning on line 214 in src/powerapi/processor/pre/k8s/k8s_pre_processor_actor.py

View check run for this annotation

Codecov / codecov/patch

src/powerapi/processor/pre/k8s/k8s_pre_processor_actor.py#L214

Added line #L214 was not covered by tests
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