Skip to content

Commit

Permalink
Disable the skip behaviour when using Harness.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Oct 4, 2024
1 parent 46ffe43 commit 6d37cca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ops/_private/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ def __init__(
self._meta,
self._model,
juju_debug_at=self._juju_context.debug_at,
# Harness tests will often have defer() usage without 'purging' the
# deferred handler with reemit(), but still expect the next emit()
# to result in a call, so we can't safely skip duplicate events.
# When behaviour matching production is required, Scenario tests
# should be used instead.
skip_duplicate_events=False,
)

warnings.warn(
Expand Down
6 changes: 5 additions & 1 deletion ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def __init__(
model: 'Model',
event_name: Optional[str] = None,
juju_debug_at: Optional[Set[str]] = None,
skip_duplicate_events: bool = True,
):
super().__init__(self, None)

Expand All @@ -624,6 +625,7 @@ def __init__(
self._event_name = event_name
self.meta = meta
self.model = model
self.skip_duplicate_events = skip_duplicate_events
# [(observer_path, method_name, parent_path, event_key)]
self._observers: _ObserverPath = []
# {observer_path: observing Object}
Expand Down Expand Up @@ -878,7 +880,9 @@ def _emit(self, event: EventBase):
continue
if _event_kind and _event_kind != event_kind:
continue
if self._event_is_in_storage(observer_path, method_name, event_path, this_event_data):
if self.skip_duplicate_events and self._event_is_in_storage(
observer_path, method_name, event_path, this_event_data
):
logger.info(
'Skipping notice (%s/%s/%s) - already in the queue.',
event_path,
Expand Down

0 comments on commit 6d37cca

Please sign in to comment.