Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67508e8

Browse files
test: attempt to make functional test startup more reliable
The functional tests have been erratic. Current theory is that we arestarting the tests before the GitLab container is fully up andrunning. * Add checking of the Health Check[1] endpoints. * Add a 20 second delay after we believe it is up and running. * Increase timeout from 300 to 400 seconds[1]https://docs.gitlab.com/ee/user/admin_area/monitoring/health_check.html
1 parent8ba97aa commit67508e8

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

‎tests/functional/conftest.py

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
importlogging
2+
importpathlib
23
importtempfile
34
importtime
45
importuuid
5-
frompathlibimportPath
66
fromsubprocessimportcheck_output
77

88
importpytest
9+
importrequests
910

1011
importgitlab
1112
importgitlab.base
1213
fromtests.functionalimporthelpers
1314

15+
SLEEP_TIME=10
16+
1417

1518
@pytest.fixture(scope="session")
16-
deffixture_dir(test_dir):
19+
deffixture_dir(test_dir)->pathlib.Path:
1720
returntest_dir/"functional"/"fixtures"
1821

1922

23+
@pytest.fixture(scope="session")
24+
defgitlab_service_name()->str:
25+
"""The "service" name is the one defined in the `docker-compose.yml` file"""
26+
return"gitlab"
27+
28+
29+
@pytest.fixture(scope="session")
30+
defgitlab_container_name()->str:
31+
"""The "container" name is the one defined in the `docker-compose.yml` file
32+
for the "gitlab" service"""
33+
return"gitlab-test"
34+
35+
36+
@pytest.fixture(scope="session")
37+
defgitlab_docker_port(docker_services,gitlab_service_name:str)->int:
38+
returndocker_services.port_for(service=gitlab_service_name,container_port=80)
39+
40+
41+
@pytest.fixture(scope="session")
42+
defgitlab_url(docker_ip:str,gitlab_docker_port:int)->str:
43+
returnf"http://{docker_ip}:{gitlab_docker_port}"
44+
45+
2046
defreset_gitlab(gl:gitlab.Gitlab)->None:
2147
"""Delete resources (such as projects, groups, users) that shouldn't
2248
exist."""
@@ -99,8 +125,8 @@ def pytest_addoption(parser):
99125

100126

101127
@pytest.fixture(scope="session")
102-
deftemp_dir():
103-
returnPath(tempfile.gettempdir())
128+
deftemp_dir()->pathlib.Path:
129+
returnpathlib.Path(tempfile.gettempdir())
104130

105131

106132
@pytest.fixture(scope="session")
@@ -129,15 +155,37 @@ def check_is_alive():
129155
Return a healthcheck function fixture for the GitLab container spinup.
130156
"""
131157

132-
def_check(container:str,start_time:float)->bool:
158+
def_check(
159+
*,
160+
container:str,
161+
start_time:float,
162+
gitlab_url:str,
163+
)->bool:
133164
setup_time=time.perf_counter()-start_time
134165
minutes,seconds=int(setup_time/60),int(setup_time%60)
135166
logging.info(
136167
f"Checking if GitLab container is up. "
137168
f"Have been checking for{minutes} minute(s),{seconds} seconds ..."
138169
)
139170
logs= ["docker","logs",container]
140-
return"gitlab Reconfigured!"incheck_output(logs).decode()
171+
if"gitlab Reconfigured!"notincheck_output(logs).decode():
172+
returnFalse
173+
logging.debug("GitLab has finished reconfiguring.")
174+
forcheckin ("health","readiness","liveness"):
175+
url=f"{gitlab_url}/-/{check}"
176+
logging.debug(f"Checking{check!r} endpoint at:{url}")
177+
try:
178+
result=requests.get(url,timeout=1.0)
179+
exceptrequests.exceptions.Timeout:
180+
logging.info(f"{check!r} check timed out")
181+
returnFalse
182+
ifresult.status_code!=200:
183+
logging.info(f"{check!r} check did not return 200:{result!r}")
184+
returnFalse
185+
logging.debug(f"{check!r} check passed:{result!r}")
186+
logging.debug(f"Sleeping for{SLEEP_TIME}")
187+
time.sleep(SLEEP_TIME)
188+
returnTrue
141189

142190
return_check
143191

@@ -167,31 +215,41 @@ def _wait(timeout=30, step=0.5):
167215

168216

169217
@pytest.fixture(scope="session")
170-
defgitlab_config(check_is_alive,docker_ip,docker_services,temp_dir,fixture_dir):
218+
defgitlab_config(
219+
check_is_alive,
220+
gitlab_container_name:str,
221+
gitlab_url:str,
222+
docker_services,
223+
temp_dir:pathlib.Path,
224+
fixture_dir:pathlib.Path,
225+
):
171226
config_file=temp_dir/"python-gitlab.cfg"
172-
port=docker_services.port_for("gitlab",80)
173227

174228
start_time=time.perf_counter()
175229
logging.info("Waiting for GitLab container to become ready.")
176230
docker_services.wait_until_responsive(
177231
timeout=300,
178232
pause=10,
179-
check=lambda:check_is_alive("gitlab-test",start_time=start_time),
233+
check=lambda:check_is_alive(
234+
container=gitlab_container_name,
235+
start_time=start_time,
236+
gitlab_url=gitlab_url,
237+
),
180238
)
181239
setup_time=time.perf_counter()-start_time
182240
minutes,seconds=int(setup_time/60),int(setup_time%60)
183241
logging.info(
184242
f"GitLab container is now ready after{minutes} minute(s),{seconds} seconds"
185243
)
186244

187-
token=set_token("gitlab-test",fixture_dir=fixture_dir)
245+
token=set_token(gitlab_container_name,fixture_dir=fixture_dir)
188246

189247
config=f"""[global]
190248
default = local
191249
timeout = 60
192250
193251
[local]
194-
url =http://{docker_ip}:{port}
252+
url ={gitlab_url}
195253
private_token ={token}
196254
api_version = 4"""
197255

@@ -208,6 +266,7 @@ def gl(gitlab_config):
208266
logging.info("Instantiating python-gitlab gitlab.Gitlab instance")
209267
instance=gitlab.Gitlab.from_config("local", [gitlab_config])
210268

269+
logging.info("Reset GitLab")
211270
reset_gitlab(instance)
212271

213272
returninstance

‎tests/functional/fixtures/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
grafana['enable'] =false
3333
letsencrypt['enable'] =false
3434
gitlab_rails['initial_license_file'] = '/python-gitlab-ci.gitlab-license'
35+
gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0']
3536
entrypoint:
3637
-/bin/sh
3738
--c

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp