Skip to content

Commit

Permalink
Fix the call to is_active_now in sink base code (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler authored May 27, 2024
1 parent d7ace4e commit 14dc03a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit 14dc03a

Please sign in to comment.