Skip to content

Commit

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

def flush_events(self) -> None:
if self.batch:
self.futures_executor.submit(self._safe_publish_event_payload_batch, self.batch)
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 @@ -9,7 +9,6 @@ def test_publish_event_no_batched(self):
executor = MagicMock()
executor.__enter__.return_value = executor
driver = MockEventListenerDriver(batched=False, futures_executor=executor)
driver.try_publish_event_payload = MagicMock(side_effect=driver.try_publish_event_payload)
mock_event_payload = MockEvent().to_dict()

driver.publish_event(mock_event_payload)
Expand All @@ -20,16 +19,15 @@ def test_publish_event_yes_batched(self):
executor = MagicMock()
executor.__enter__.return_value = executor
driver = MockEventListenerDriver(batched=True, futures_executor=executor)
driver.try_publish_event_payload_batch = MagicMock(side_effect=driver.try_publish_event_payload)
mock_event_payload = MockEvent().to_dict()

# Publish 9 events to fill the batch
mock_event_payloads = [mock_event_payload for _ in range(0, 9)]
for mock_event_payload in mock_event_payloads:
driver.publish_event(mock_event_payload)

assert len(driver._batch) == 9
executor.submit.assert_not_called()
driver.try_publish_event_payload_batch.assert_not_called()

# Publish the 10th event to trigger the batch publish
driver.publish_event(mock_event_payload)
Expand Down

0 comments on commit 9782a3f

Please sign in to comment.