|
1 | 1 | import asyncio |
2 | | -import os |
3 | 2 | from collections.abc import AsyncGenerator, Callable |
4 | 3 | from contextlib import asynccontextmanager |
5 | 4 | from itertools import starmap |
6 | | -from typing import Final |
| 5 | +from typing import Final, cast |
7 | 6 | from uuid import uuid4 |
8 | 7 |
|
9 | 8 | import pytest |
|
21 | 20 | parse_header, |
22 | 21 | ) |
23 | 22 |
|
24 | | -pytestmark = pytest.mark.anyio |
| 23 | +DESTINATION: Final = "DLQ" |
| 24 | + |
25 | 25 |
|
26 | | -CONNECTION_PARAMETERS: Final = stompman.ConnectionParameters( |
27 | | - host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode=":=123" |
| 26 | +@pytest.fixture( |
| 27 | + params=[ |
| 28 | + stompman.ConnectionParameters(host="activemq-artemis", port=61616, login="admin", passcode=":=123"), |
| 29 | + stompman.ConnectionParameters(host="activemq-classic", port=61613, login="admin", passcode=":=123"), |
| 30 | + ] |
28 | 31 | ) |
29 | | -DESTINATION: Final = "DLQ" |
| 32 | +def connection_parameters(request: pytest.FixtureRequest) -> stompman.ConnectionParameters: |
| 33 | + return cast(stompman.ConnectionParameters, request.param) |
30 | 34 |
|
31 | 35 |
|
32 | 36 | @asynccontextmanager |
33 | | -async def create_client() -> AsyncGenerator[stompman.Client, None]: |
| 37 | +async def create_client(connection_parameters: stompman.ConnectionParameters) -> AsyncGenerator[stompman.Client, None]: |
34 | 38 | async with stompman.Client( |
35 | | - servers=[CONNECTION_PARAMETERS], read_timeout=10, connection_confirmation_timeout=10 |
| 39 | + servers=[connection_parameters], read_timeout=10, connection_confirmation_timeout=10 |
36 | 40 | ) as client: |
37 | 41 | yield client |
38 | 42 |
|
39 | 43 |
|
40 | | -async def test_ok() -> None: |
| 44 | +@pytest.mark.anyio |
| 45 | +async def test_ok(connection_parameters: stompman.ConnectionParameters) -> None: |
41 | 46 | async def produce() -> None: |
42 | 47 | for message in messages[200:]: |
43 | 48 | await producer.send(body=message, destination=DESTINATION, headers={"hello": "from outside transaction"}) |
@@ -65,7 +70,11 @@ async def handle_message(frame: stompman.MessageFrame) -> None: # noqa: RUF029 |
65 | 70 |
|
66 | 71 | messages = [str(uuid4()).encode() for _ in range(10000)] |
67 | 72 |
|
68 | | - async with create_client() as consumer, create_client() as producer, asyncio.TaskGroup() as task_group: |
| 73 | + async with ( |
| 74 | + create_client(connection_parameters) as consumer, |
| 75 | + create_client(connection_parameters) as producer, |
| 76 | + asyncio.TaskGroup() as task_group, |
| 77 | + ): |
69 | 78 | task_group.create_task(consume()) |
70 | 79 | task_group.create_task(produce()) |
71 | 80 |
|
|
0 commit comments