pytest-kafka-broker 0.3.1__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_kafka_broker/__init__.py +35 -3
- {pytest_kafka_broker-0.3.1.dist-info → pytest_kafka_broker-0.4.0.dist-info}/METADATA +1 -1
- pytest_kafka_broker-0.4.0.dist-info/RECORD +7 -0
- pytest_kafka_broker-0.3.1.dist-info/RECORD +0 -7
- {pytest_kafka_broker-0.3.1.dist-info → pytest_kafka_broker-0.4.0.dist-info}/WHEEL +0 -0
- {pytest_kafka_broker-0.3.1.dist-info → pytest_kafka_broker-0.4.0.dist-info}/entry_points.txt +0 -0
- {pytest_kafka_broker-0.3.1.dist-info → pytest_kafka_broker-0.4.0.dist-info}/top_level.txt +0 -0
pytest_kafka_broker/__init__.py
CHANGED
|
@@ -2,7 +2,9 @@ import asyncio
|
|
|
2
2
|
import subprocess
|
|
3
3
|
from collections.abc import AsyncGenerator
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
+
from errno import EADDRINUSE
|
|
5
6
|
from pathlib import Path
|
|
7
|
+
from socket import socket
|
|
6
8
|
from tarfile import TarFile
|
|
7
9
|
from tempfile import TemporaryDirectory
|
|
8
10
|
from uuid import uuid4
|
|
@@ -75,6 +77,36 @@ config
|
|
|
75
77
|
"""
|
|
76
78
|
|
|
77
79
|
|
|
80
|
+
def _unused_tcp_port(default: int = 0) -> int:
|
|
81
|
+
with socket() as sock:
|
|
82
|
+
try:
|
|
83
|
+
sock.bind(("127.0.0.1", default))
|
|
84
|
+
except OSError as e:
|
|
85
|
+
if e.errno != EADDRINUSE:
|
|
86
|
+
raise
|
|
87
|
+
sock.bind(("127.0.0.1", 0))
|
|
88
|
+
_, port = sock.getsockname()
|
|
89
|
+
return port
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@pytest.fixture
|
|
93
|
+
def find_unused_tcp_port():
|
|
94
|
+
"""Unused TCP port factory.
|
|
95
|
+
|
|
96
|
+
This is similar to `unused_tcp_port_factory` from pytest_asyncio, but it
|
|
97
|
+
supports a default port argument, and is not session-scoped.
|
|
98
|
+
"""
|
|
99
|
+
used = set()
|
|
100
|
+
|
|
101
|
+
def factory(default: int = 0) -> int:
|
|
102
|
+
while (port := _unused_tcp_port(default)) in used:
|
|
103
|
+
pass
|
|
104
|
+
used.add(port)
|
|
105
|
+
return port
|
|
106
|
+
|
|
107
|
+
return factory
|
|
108
|
+
|
|
109
|
+
|
|
78
110
|
@dataclass
|
|
79
111
|
class KafkaBrokerContext:
|
|
80
112
|
"""Information and convenience methods for a temporary Kafka cluster.
|
|
@@ -120,7 +152,7 @@ del _doc
|
|
|
120
152
|
|
|
121
153
|
@pytest_asyncio.fixture
|
|
122
154
|
async def kafka_broker(
|
|
123
|
-
kafka_home, tmp_path,
|
|
155
|
+
kafka_home, tmp_path, find_unused_tcp_port
|
|
124
156
|
) -> AsyncGenerator[KafkaBrokerContext]:
|
|
125
157
|
"""Pytest fixture to run a local, temporary Kafka broker."""
|
|
126
158
|
kafka_storage = kafka_home / "bin" / "kafka-storage.sh"
|
|
@@ -131,8 +163,8 @@ async def kafka_broker(
|
|
|
131
163
|
log_path = tmp_path / "log"
|
|
132
164
|
log_path.mkdir()
|
|
133
165
|
env = {"LOG_DIR": str(log_path)}
|
|
134
|
-
plaintext_port =
|
|
135
|
-
controller_port =
|
|
166
|
+
plaintext_port = find_unused_tcp_port(9092)
|
|
167
|
+
controller_port = find_unused_tcp_port(9093)
|
|
136
168
|
config_path.write_text(
|
|
137
169
|
f"""
|
|
138
170
|
process.roles=broker,controller
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pytest_kafka_broker/__init__.py,sha256=c3QqN1zeed-X-IoL1aAKqY6h10GfGpkuo1-WJEBKuVs,7310
|
|
2
|
+
pytest_kafka_broker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
pytest_kafka_broker-0.4.0.dist-info/METADATA,sha256=kSMiKX3AjTfzvBbOPUaOxyK36IA-SM0MWRuaHE-18SA,683
|
|
4
|
+
pytest_kafka_broker-0.4.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
+
pytest_kafka_broker-0.4.0.dist-info/entry_points.txt,sha256=mjFsRbu6FOiZkUOlSaXpo4QdLHwniNB-p_NEIgRbDnw,46
|
|
6
|
+
pytest_kafka_broker-0.4.0.dist-info/top_level.txt,sha256=nTrYx9xVeK5hsqbhBRL2bgBV_ea-J66_f4Dk8eD-Ci0,20
|
|
7
|
+
pytest_kafka_broker-0.4.0.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
pytest_kafka_broker/__init__.py,sha256=1-dEGoWlajumAl7AWsYARbxi9wKlBwTh56sg1KSLC5g,6511
|
|
2
|
-
pytest_kafka_broker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
pytest_kafka_broker-0.3.1.dist-info/METADATA,sha256=_31JrO09YK79CS6ly65rCWZdQEuaFcF_dUBG7lKx-KE,683
|
|
4
|
-
pytest_kafka_broker-0.3.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
-
pytest_kafka_broker-0.3.1.dist-info/entry_points.txt,sha256=mjFsRbu6FOiZkUOlSaXpo4QdLHwniNB-p_NEIgRbDnw,46
|
|
6
|
-
pytest_kafka_broker-0.3.1.dist-info/top_level.txt,sha256=nTrYx9xVeK5hsqbhBRL2bgBV_ea-J66_f4Dk8eD-Ci0,20
|
|
7
|
-
pytest_kafka_broker-0.3.1.dist-info/RECORD,,
|
|
File without changes
|
{pytest_kafka_broker-0.3.1.dist-info → pytest_kafka_broker-0.4.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|