mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-02-20 15:19:08 -06:00
* feat: factor out async to sync * feat: remove global event loop setter in workflow listener * fix: rm more global loop sets * fix: more loop sets * fix: more * fix: more * fix: rm one more * fix: stream from thread * fix: dispatcher * fix: make tests have independent loop scopes (woohoo!) * feat: use default loop scope * fix: try adding back tests * Revert "fix: try adding back tests" This reverts commit bed34a9bae539650e4fe32e0518aa9d1c5c0af5c. * fix: rm dead code * fix: remove redundant `_utils` * fix: add typing to client stubs + regenerate * fix: create more clients lazily * fix: print cruft * chore: version * fix: lint
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import pytest
|
|
|
|
from hatchet_sdk.clients.events import BulkPushEventOptions, BulkPushEventWithMetadata
|
|
from hatchet_sdk.hatchet import Hatchet
|
|
|
|
|
|
# requires scope module or higher for shared event loop
|
|
@pytest.mark.asyncio()
|
|
async def test_event_push(hatchet: Hatchet) -> None:
|
|
e = hatchet.event.push("user:create", {"test": "test"})
|
|
|
|
assert e.eventId is not None
|
|
|
|
|
|
@pytest.mark.asyncio()
|
|
async def test_async_event_push(aiohatchet: Hatchet) -> None:
|
|
e = await aiohatchet.event.aio_push("user:create", {"test": "test"})
|
|
|
|
assert e.eventId is not None
|
|
|
|
|
|
@pytest.mark.asyncio()
|
|
async def test_async_event_bulk_push(aiohatchet: Hatchet) -> None:
|
|
|
|
events = [
|
|
BulkPushEventWithMetadata(
|
|
key="event1",
|
|
payload={"message": "This is event 1"},
|
|
additional_metadata={"source": "test", "user_id": "user123"},
|
|
),
|
|
BulkPushEventWithMetadata(
|
|
key="event2",
|
|
payload={"message": "This is event 2"},
|
|
additional_metadata={"source": "test", "user_id": "user456"},
|
|
),
|
|
BulkPushEventWithMetadata(
|
|
key="event3",
|
|
payload={"message": "This is event 3"},
|
|
additional_metadata={"source": "test", "user_id": "user789"},
|
|
),
|
|
]
|
|
opts = BulkPushEventOptions(namespace="bulk-test")
|
|
|
|
e = await aiohatchet.event.aio_bulk_push(events, opts)
|
|
|
|
assert len(e) == 3
|
|
|
|
# Sort both lists of events by their key to ensure comparison order
|
|
sorted_events = sorted(events, key=lambda x: x.key)
|
|
sorted_returned_events = sorted(e, key=lambda x: x.key)
|
|
namespace = "bulk-test"
|
|
|
|
# Check that the returned events match the original events
|
|
for original_event, returned_event in zip(sorted_events, sorted_returned_events):
|
|
assert returned_event.key == namespace + original_event.key
|