GeezerVison is showing github.com — tests: start every server test on a free port (#466) · humemai/arcadedb-embedded-python@fe4aa86
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bindings/python/tests/conftest.py +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,6 +110,23 @@ def pytest_runtest_call(item): | 110 | 110 | TEST_PASSWORD = "test12345" # nosec B105 | 111 | 111 |
| 112 | 112 |
| | 113 | +def free_port(): | | 114 | + """A free local TCP port, for a server's ``http_port``. | | 115 | +
| | 116 | + The server's default is the fixed port 2480, so a test that starts a server | | 117 | + without choosing a port fails with "Unable to listen to a HTTP port in the | | 118 | + configured port range 2480 - 2480" whenever anything else on the machine | | 119 | + holds 2480 (the laptop, 2026-10-22). Every test that starts a server passes | | 120 | + ``config={"http_port": free_port()}``. For several distinct ports at once, | | 121 | + see ``_free_ports`` in test_server_wire_protocols.py. | | 122 | + """ | | 123 | + import socket | | 124 | + | | 125 | + with socket.socket() as s: | | 126 | + s.bind(("127.0.0.1", 0)) | | 127 | + return s.getsockname()[1] | | 128 | + | | 129 | + | 113 | 130 | @pytest.fixture | 114 | 131 | def temp_server_root(): | 115 | 132 | """Create a temporary server root directory.""" | |
Collapse file Copy file name to clipboardExpand all lines: bindings/python/tests/test_server.py +11-7Lines changed: 11 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 |
| 17 | 17 | import pytest | 18 | 18 | from arcadedb_embedded import ArcadeDBServer | 19 | | -from tests.conftest import TEST_PASSWORD | | 19 | +from tests.conftest import TEST_PASSWORD, free_port | 20 | 20 |
| 21 | 21 |
| 22 | 22 | @pytest.mark.server | 23 | 23 | def test_server_creation(temp_server_root): | 24 | 24 | """Test creating and starting a server.""" | | 25 | + port = free_port() | 25 | 26 | server = ArcadeDBServer( | 26 | 27 | root_path=temp_server_root, | 27 | 28 | root_password=TEST_PASSWORD, | 28 | | - config={"http_port": 2480}, | | 29 | + config={"http_port": port}, | 29 | 30 | ) | 30 | 31 |
| 31 | 32 | assert not server.is_started() | @@ -35,10 +36,10 @@ def test_server_creation(temp_server_root): | 35 | 36 | # Give server a moment to start | 36 | 37 | time.sleep(1) | 37 | 38 |
| 38 | | - assert server.get_http_port() == 2480 | | 39 | + assert server.get_http_port() == port | 39 | 40 | studio_url = server.get_studio_url() | 40 | 41 | assert "http://" in studio_url | 41 | | - assert "2480" in studio_url | | 42 | + assert str(port) in studio_url | 42 | 43 |
| 43 | 44 | server.stop() | 44 | 45 | assert not server.is_started() | @@ -55,7 +56,9 @@ def test_server_database_operations(temp_server_root): | 55 | 56 | - Operations within same Python process (embedded access) | 56 | 57 | """ | 57 | 58 | with ArcadeDBServer( | 58 | | - root_path=temp_server_root, root_password=TEST_PASSWORD | | 59 | + root_path=temp_server_root, | | 60 | + root_password=TEST_PASSWORD, | | 61 | + config={"http_port": free_port()}, | 59 | 62 | ) as server: | 60 | 63 | # Server auto-starts in context manager | 61 | 64 | time.sleep(1) | @@ -84,15 +87,16 @@ def test_server_database_operations(temp_server_root): | 84 | 87 | @pytest.mark.server | 85 | 88 | def test_server_custom_config(temp_server_root): | 86 | 89 | """Test server with custom configuration.""" | 87 | | - config = {"http_port": 8080, "host": "127.0.0.1", "mode": "production"} | | 90 | + port = free_port() | | 91 | + config = {"http_port": port, "host": "127.0.0.1", "mode": "production"} | 88 | 92 |
| 89 | 93 | server = ArcadeDBServer( | 90 | 94 | root_path=temp_server_root, root_password=TEST_PASSWORD, config=config | 91 | 95 | ) | 92 | 96 | server.start() | 93 | 97 | time.sleep(1) | 94 | 98 |
| 95 | | - assert server.get_http_port() == 8080 | | 99 | + assert server.get_http_port() == port | 96 | 100 |
| 97 | 101 | server.stop() | 98 | 102 |
| |
Collapse file Copy file name to clipboardExpand all lines: bindings/python/tests/test_server_http_endpoints.py +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 |
| 12 | 12 | import arcadedb_embedded as arcadedb | 13 | 13 | import pytest | 14 | | -from tests.conftest import TEST_PASSWORD | | 14 | +from tests.conftest import TEST_PASSWORD, free_port | 15 | 15 |
| 16 | 16 |
| 17 | 17 | @pytest.fixture | 18 | 18 | def http_server(tmp_path): | 19 | 19 | requests = pytest.importorskip("requests") | 20 | 20 | server = arcadedb.create_server( | 21 | | - root_path=str(tmp_path / "srv"), root_password=TEST_PASSWORD | | 21 | + root_path=str(tmp_path / "srv"), | | 22 | + root_password=TEST_PASSWORD, | | 23 | + config={"http_port": free_port()}, | 22 | 24 | ) | 23 | 25 | server.start() | 24 | 26 | time.sleep(1) | |
Collapse file Copy file name to clipboardExpand all lines: bindings/python/tests/test_server_packaging.py +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,10 +109,12 @@ def test_server_starts_and_serves_http(temp_server_root): | 109 | 109 | """ | 110 | 110 | requests = pytest.importorskip("requests") | 111 | 111 | from arcadedb_embedded import create_server | 112 | | - from tests.conftest import TEST_PASSWORD | | 112 | + from tests.conftest import TEST_PASSWORD, free_port | 113 | 113 |
| 114 | 114 | with create_server( | 115 | | - root_path=temp_server_root, root_password=TEST_PASSWORD | | 115 | + root_path=temp_server_root, | | 116 | + root_password=TEST_PASSWORD, | | 117 | + config={"http_port": free_port()}, | 116 | 118 | ) as server: | 117 | 119 | assert server.is_started() | 118 | 120 | port = server.get_http_port() | @@ -156,10 +158,12 @@ def served(temp_server_root): | 156 | 158 | """A started server, a database named ``packaging``, and an authenticated session.""" | 157 | 159 | import requests | 158 | 160 | from arcadedb_embedded import create_server | 159 | | - from tests.conftest import TEST_PASSWORD | | 161 | + from tests.conftest import TEST_PASSWORD, free_port | 160 | 162 |
| 161 | 163 | with create_server( | 162 | | - root_path=temp_server_root, root_password=TEST_PASSWORD | | 164 | + root_path=temp_server_root, | | 165 | + root_password=TEST_PASSWORD, | | 166 | + config={"http_port": free_port()}, | 163 | 167 | ) as server: | 164 | 168 | server.create_database("packaging").close() | 165 | 169 | session = requests.Session() | |
Collapse file Copy file name to clipboardExpand all lines: bindings/python/tests/test_server_patterns.py +29-7Lines changed: 29 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 |
| 21 | 21 | import arcadedb_embedded as arcadedb | 22 | 22 | import pytest | 23 | | -from tests.conftest import TEST_PASSWORD | | 23 | +from tests.conftest import TEST_PASSWORD, free_port | 24 | 24 |
| 25 | 25 |
| 26 | 26 | def _http_query(server, db_name, sql): | @@ -94,7 +94,11 @@ def test_server_pattern_recommended(cleanup_test_dirs): | 94 | 94 |
| 95 | 95 | # Step 1: Start server first | 96 | 96 | print("\n1. Starting ArcadeDB server...") | 97 | | - server = arcadedb.create_server(root_path=root_path, root_password=TEST_PASSWORD) | | 97 | + server = arcadedb.create_server( | | 98 | + root_path=root_path, | | 99 | + root_password=TEST_PASSWORD, | | 100 | + config={"http_port": free_port()}, | | 101 | + ) | 98 | 102 | register_server(server) | 99 | 103 | server.start() | 100 | 104 | assert server.is_started() | @@ -153,7 +157,11 @@ def test_server_thread_safety(cleanup_test_dirs): | 153 | 157 |
| 154 | 158 | # Start server and create database | 155 | 159 | print("\n1. Setting up server and database...") | 156 | | - server = arcadedb.create_server(root_path=root_path, root_password=TEST_PASSWORD) | | 160 | + server = arcadedb.create_server( | | 161 | + root_path=root_path, | | 162 | + root_password=TEST_PASSWORD, | | 163 | + config={"http_port": free_port()}, | | 164 | + ) | 157 | 165 | register_server(server) | 158 | 166 | server.start() | 159 | 167 |
| @@ -229,7 +237,9 @@ def test_server_context_manager(cleanup_test_dirs): | 229 | 237 |
| 230 | 238 | # Server automatically starts and stops | 231 | 239 | with arcadedb.create_server( | 232 | | - root_path=root_path, root_password=TEST_PASSWORD | | 240 | + root_path=root_path, | | 241 | + root_password=TEST_PASSWORD, | | 242 | + config={"http_port": free_port()}, | 233 | 243 | ) as server: | 234 | 244 | print(" ✅ Server started (automatic)") | 235 | 245 |
| @@ -306,7 +316,11 @@ def test_pattern1_embedded_first_requires_close(cleanup_test_dirs): | 306 | 316 |
| 307 | 317 | # Step 4: Start server | 308 | 318 | print("\n4. Starting ArcadeDB server...") | 309 | | - server = arcadedb.create_server(root_path=root_path, root_password=TEST_PASSWORD) | | 319 | + server = arcadedb.create_server( | | 320 | + root_path=root_path, | | 321 | + root_password=TEST_PASSWORD, | | 322 | + config={"http_port": free_port()}, | | 323 | + ) | 310 | 324 | register_server(server) | 311 | 325 | server.start() | 312 | 326 | print(f" ✅ Server started on port {server.get_http_port()}") | @@ -442,7 +456,11 @@ def test_embedded_performance_comparison(cleanup_test_dirs): | 442 | 456 | print("\n2. Server-Managed Embedded Mode (same process)...") | 443 | 457 | server_path = create_temp_dir("server_perf_") | 444 | 458 |
| 445 | | - server = arcadedb.create_server(root_path=server_path, root_password=TEST_PASSWORD) | | 459 | + server = arcadedb.create_server( | | 460 | + root_path=server_path, | | 461 | + root_password=TEST_PASSWORD, | | 462 | + config={"http_port": free_port()}, | | 463 | + ) | 446 | 464 | register_server(server) | 447 | 465 | server.start() | 448 | 466 |
| @@ -538,7 +556,11 @@ def test_http_api_access_pattern(cleanup_test_dirs): | 538 | 556 |
| 539 | 557 | # Step 1: Start server (required for HTTP API) | 540 | 558 | print("\n1. Starting ArcadeDB server...") | 541 | | - server = arcadedb.create_server(root_path=root_path, root_password=TEST_PASSWORD) | | 559 | + server = arcadedb.create_server( | | 560 | + root_path=root_path, | | 561 | + root_password=TEST_PASSWORD, | | 562 | + config={"http_port": free_port()}, | | 563 | + ) | 542 | 564 | register_server(server) | 543 | 565 | server.start() | 544 | 566 | time.sleep(1) # Give server time to fully start | |
|