55import pytest
66import requests
77
8- MAX_CONTAINER_STARTUP_TIME = 30
8+ MAX_CONTAINER_STARTUP_TIME = 120 # Increased from 30 to 120 seconds for slower systems
9+
10+ # Check if a local TerminusDB test server is already running
11+ def is_local_server_running ():
12+ """Check if local TerminusDB server is running at http://127.0.0.1:6363"""
13+ try :
14+ response = requests .get ("http://127.0.0.1:6363" , timeout = 2 )
15+ # Server responds with 404 for root path, which means it's running
16+ return response .status_code in [200 , 404 ]
17+ except (requests .exceptions .ConnectionError , requests .exceptions .Timeout ):
18+ return False
19+
20+
21+ def is_docker_server_running ():
22+ """Check if Docker TerminusDB server is already running at http://127.0.0.1:6366"""
23+ try :
24+ response = requests .get ("http://127.0.0.1:6366" , timeout = 2 )
25+ # Server responds with 404 for root path, which means it's running
26+ return response .status_code in [200 , 404 ]
27+ except (requests .exceptions .ConnectionError , requests .exceptions .Timeout ):
28+ return False
29+
30+
31+ def is_jwt_server_running ():
32+ """Check if JWT Docker TerminusDB server is already running at http://127.0.0.1:6367"""
33+ try :
34+ response = requests .get ("http://127.0.0.1:6367" , timeout = 2 )
35+ # Server responds with 404 for root path, which means it's running
36+ return response .status_code in [200 , 404 ]
37+ except (requests .exceptions .ConnectionError , requests .exceptions .Timeout ):
38+ return False
939
1040
1141def is_docker_installed ():
@@ -39,6 +69,13 @@ def docker_url_jwt(pytestconfig):
3969 # we are using subprocess in case we need to access some of the outputs
4070 # most likely
4171 jwt_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRlc3RrZXkifQ.eyJodHRwOi8vdGVybWludXNkYi5jb20vc2NoZW1hL3N5c3RlbSNhZ2VudF9uYW1lIjoiYWRtaW4iLCJodHRwOi8vdGVybWludXNkYi5jb20vc2NoZW1hL3N5c3RlbSN1c2VyX2lkZW50aWZpZXIiOiJhZG1pbkB1c2VyLmNvbSIsImlzcyI6Imh0dHBzOi8vdGVybWludXNodWIuZXUuYXV0aDAuY29tLyIsInN1YiI6ImFkbWluIiwiYXVkIjpbImh0dHBzOi8vdGVybWludXNodWIvcmVnaXN0ZXJVc2VyIiwiaHR0cHM6Ly90ZXJtaW51c2h1Yi5ldS5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNTkzNzY5MTgzLCJhenAiOiJNSkpuZEdwMHpVZE03bzNQT1RRUG1SSkltWTJobzBhaSIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwifQ.Ru03Bi6vSIQ57bC41n6fClSdxlb61m0xX6Q34Yh91gql0_CyfYRWTuqzqPMFoCefe53hPC5E-eoSFdID_u6w1ih_pH-lTTqus9OWgi07Qou3QNs8UZBLiM4pgLqcBKs0N058jfg4y6h9GjIBGVhX9Ni2ez3JGNcz1_U45BhnreE"
72+
73+ # Check if JWT server is already running (port 6367)
74+ if is_jwt_server_running ():
75+ print ("\n ✓ Using existing JWT Docker TerminusDB server at http://127.0.0.1:6367" )
76+ yield ("http://127.0.0.1:6367" , jwt_token )
77+ return # Don't clean up - server was already running
78+
4279 pytestconfig .getoption ("docker_compose" )
4380 output = subprocess .run (
4481 [
@@ -77,7 +114,8 @@ def docker_url_jwt(pytestconfig):
77114 if service .stdout == b"terminusdb-server\n " :
78115 try :
79116 response = requests .get (test_url )
80- assert response .status_code == 200
117+ # Server responds with 404 for root path, which means it's running
118+ assert response .status_code in [200 , 404 ]
81119 break
82120 except (requests .exceptions .ConnectionError , AssertionError ):
83121 pass
@@ -87,16 +125,37 @@ def docker_url_jwt(pytestconfig):
87125
88126 if seconds_waited > MAX_CONTAINER_STARTUP_TIME :
89127 clean_up_container ()
90- raise RuntimeError (" Container was to slow to startup" )
128+ raise RuntimeError (f"JWT Container was too slow to startup (waited { MAX_CONTAINER_STARTUP_TIME } s) " )
91129
92130 yield (test_url , jwt_token )
93131 clean_up_container ()
94132
95133
96134@pytest .fixture (scope = "module" )
97135def docker_url (pytestconfig ):
98- # we are using subprocess in case we need to access some of the outputs
99- # most likely
136+ """
137+ Provides a TerminusDB server URL for integration tests.
138+ Prefers local test server if running, otherwise starts Docker container.
139+
140+ NOTE: This fixture returns just the URL. Tests expect AUTOLOGIN mode (no authentication).
141+ If using local server with authentication, use TERMINUSDB_AUTOLOGIN=true when starting it.
142+ """
143+ # Check if local test server is already running (port 6363)
144+ if is_local_server_running ():
145+ print ("\n ✓ Using existing local TerminusDB test server at http://127.0.0.1:6363" )
146+ print ("⚠️ WARNING: Local server should be started with TERMINUSDB_AUTOLOGIN=true" )
147+ print (" Or use: TERMINUSDB_SERVER_AUTOLOGIN=true ./tests/terminusdb-test-server.sh restart" )
148+ yield "http://127.0.0.1:6363"
149+ return # Don't clean up - server was already running
150+
151+ # Check if Docker container is already running (port 6366)
152+ if is_docker_server_running ():
153+ print ("\n ✓ Using existing Docker TerminusDB server at http://127.0.0.1:6366" )
154+ yield "http://127.0.0.1:6366"
155+ return # Don't clean up - server was already running
156+
157+ # No server found, start Docker container
158+ print ("\n ⚠ No server found, starting Docker container with AUTOLOGIN..." )
100159 pytestconfig .getoption ("docker_compose" )
101160 output = subprocess .run (
102161 [
@@ -134,7 +193,9 @@ def docker_url(pytestconfig):
134193 if service .stdout == b"terminusdb-server\n " :
135194 try :
136195 response = requests .get (test_url )
137- assert response .status_code == 200
196+ # Server responds with 404 for root path, which means it's running
197+ assert response .status_code in [200 , 404 ]
198+ print (f"✓ Docker container started successfully after { seconds_waited } s" )
138199 break
139200 except (requests .exceptions .ConnectionError , AssertionError ):
140201 pass
@@ -144,7 +205,7 @@ def docker_url(pytestconfig):
144205
145206 if seconds_waited > MAX_CONTAINER_STARTUP_TIME :
146207 clean_up_container ()
147- raise RuntimeError ("Container was to slow to startup" )
208+ raise RuntimeError (f "Container was too slow to startup (waited { MAX_CONTAINER_STARTUP_TIME } s) " )
148209
149210 yield test_url
150211 clean_up_container ()
0 commit comments