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 the call to is_active_now in sink base code #1440

Merged
merged 1 commit into from
May 27, 2024
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
2 changes: 1 addition & 1 deletion src/robusta/core/sinks/sink_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def stop(self):
def accepts(self, finding: Finding) -> bool:
return (
finding.matches(self.params.match, self.params.scope)
and any(time_slice.is_active_now for time_slice in self.time_slices)
and any(time_slice.is_active_now() for time_slice in self.time_slices)
)

@abstractmethod
Expand Down
34 changes: 34 additions & 0 deletions tests/test_sink_timing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.mock import Mock

import pytest
from freezegun import freeze_time

from robusta.core.reporting import Finding
from robusta.core.sinks.sink_base import SinkBase
from robusta.core.sinks.sink_base_params import ActivityParams
from robusta.core.sinks.timing import TimeSlice


Expand Down Expand Up @@ -32,3 +37,32 @@ def test_invalid_days(self):
def test_invalid_time(self, time):
with pytest.raises(ValueError):
TimeSlice([], [time], "UTC")


class _TestSinkBase(SinkBase):
def write_finding(self, finding: Finding, platform_enabled: bool):
pass

def create_summary_header(self):
pass

def _build_time_slices_from_params(self, params: ActivityParams):
# We'll construct time_slices explicitly below in TestSinkBase.test_accepts
pass


class TestSinkBase:
@pytest.mark.parametrize(
"days,time_intervals,expected_result",
[
(["mon", "tue"], [("10:10", "11:05"), ("13:05", "13:50")], False),
(["Sun", "Wed"], [("13:30", "14:00"), ("19:01", "21:30")], True),
]
)
def test_accepts(self, days, time_intervals, expected_result):
mock_registry = Mock(get_global_config=lambda: Mock())
sink = _TestSinkBase(registry=mock_registry, sink_params=Mock())
sink.time_slices = [TimeSlice(days, time_intervals, "UTC")]
mock_finding = Mock(matches=Mock(return_value=True))
with freeze_time("2012-01-01 13:45"): # this is UTC time
assert sink.accepts(mock_finding) is expected_result
Loading