Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Oct 11, 2024
1 parent adb32b9 commit f794eb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions griptape/drivers/event_listener/base_event_listener_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def publish_event(self, event: BaseEvent | dict) -> None:
self.futures_executor.submit(self._safe_publish_event_payload, event_payload)

def flush_events(self) -> None:
self.futures_executor.submit(self._safe_publish_event_payload_batch, self.batch)
self._batch = []
if self.batch:
self.futures_executor.submit(self._safe_publish_event_payload_batch, self.batch)
self._batch = []

@abstractmethod
def try_publish_event_payload(self, event_payload: dict) -> None: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_flush_events(self):
driver = MockEventListenerDriver(batched=True, futures_executor=executor)
driver.try_publish_event_payload_batch = MagicMock(side_effect=driver.try_publish_event_payload)

driver.flush_events()
driver.try_publish_event_payload_batch.assert_not_called()
assert driver.batch == []
mock_event_payloads = [MockEvent().to_dict() for _ in range(0, 3)]
for mock_event_payload in mock_event_payloads:
driver.publish_event(mock_event_payload)
Expand Down

0 comments on commit f794eb1

Please sign in to comment.