This is an automated email from the ASF dual-hosted git repository.
honahx pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new 1befad7 Fix moto server port conflict (#292)
1befad7 is described below
commit 1befad70bb72e649ec07431a43972aa2cd0cc0da
Author: Kevin Liu <[email protected]>
AuthorDate: Sun Jan 21 16:16:57 2024 -0800
Fix moto server port conflict (#292)
- Change moto server port to 5001
- Throw a meaningful exception when port conflict detected
---
tests/conftest.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tests/conftest.py b/tests/conftest.py
index 07beba0..9c53301 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -27,6 +27,7 @@ retrieved using `request.getfixturevalue(fixture_name)`.
import os
import re
+import socket
import string
import uuid
from datetime import datetime
@@ -1587,7 +1588,7 @@ def fixture_aws_credentials() -> Generator[None, None,
None]:
os.environ.pop("AWS_DEFAULT_REGION")
-MOTO_SERVER = ThreadedMotoServer(ip_address="localhost", port=5000)
+MOTO_SERVER = ThreadedMotoServer(ip_address="localhost", port=5001)
def pytest_sessionfinish(
@@ -1600,10 +1601,17 @@ def pytest_sessionfinish(
@pytest.fixture(scope="session")
def moto_server() -> ThreadedMotoServer:
+ # this will throw an exception if the port is already in use
+ is_port_in_use(MOTO_SERVER._ip_address, MOTO_SERVER._port)
MOTO_SERVER.start()
return MOTO_SERVER
+def is_port_in_use(ip_address: str, port: int) -> None:
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+ s.bind((ip_address, port))
+
+
@pytest.fixture(scope="session")
def moto_endpoint_url(moto_server: ThreadedMotoServer) -> str:
_url = f"http://{moto_server._ip_address}:{moto_server._port}"