Skip to content

Commit 5372e25

Browse files
PythonFZdanfimov
authored andcommitted
test inmemory broker middleware startup / shutdown handlers
1 parent c4b8666 commit 5372e25

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎tests/brokers/test_inmemory.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from taskiq import InMemoryBroker
7+
from taskiq.abc.middleware import TaskiqMiddleware
78
from taskiq.events import TaskiqEvents
89
from taskiq.state import TaskiqState
910

@@ -66,6 +67,24 @@ async def _c_startup(state: TaskiqState) -> None:
6667
assert broker.state.from_client == test_value
6768

6869

70+
async def test_middleware_startup_and_shutdown_fire() -> None:
71+
calls = []
72+
73+
class RecordingMiddleware(TaskiqMiddleware):
74+
async def startup(self) -> None:
75+
calls.append("startup")
76+
77+
async def shutdown(self) -> None:
78+
calls.append("shutdown")
79+
80+
broker = InMemoryBroker().with_middlewares(RecordingMiddleware())
81+
82+
await broker.startup()
83+
await broker.shutdown()
84+
85+
assert calls == ["startup", "shutdown"]
86+
87+
6988
async def test_execution() -> None:
7089
broker = InMemoryBroker()
7190
test_value = uuid.uuid4().hex

0 commit comments

Comments
 (0)