|
6 | 6 | from subprocess import check_output |
7 | 7 |
|
8 | 8 | import pytest |
| 9 | +import requests |
9 | 10 |
|
10 | 11 | import gitlab |
11 | 12 | import gitlab.base |
12 | 13 | from tests.functional import helpers |
13 | 14 |
|
| 15 | +SLEEP_TIME = 20 |
| 16 | + |
14 | 17 |
|
15 | 18 | @pytest.fixture(scope="session") |
16 | 19 | def fixture_dir(test_dir): |
@@ -129,15 +132,30 @@ def check_is_alive(): |
129 | 132 | Return a healthcheck function fixture for the GitLab container spinup. |
130 | 133 | """ |
131 | 134 |
|
132 | | - def _check(container: str, start_time: float) -> bool: |
| 135 | + def _check( |
| 136 | + *, container: str, start_time: float, docker_ip: str, docker_port: int |
| 137 | + ) -> bool: |
133 | 138 | setup_time = time.perf_counter() - start_time |
134 | 139 | minutes, seconds = int(setup_time / 60), int(setup_time % 60) |
135 | 140 | logging.info( |
136 | 141 | f"Checking if GitLab container is up. " |
137 | 142 | f"Have been checking for {minutes} minute(s), {seconds} seconds ..." |
138 | 143 | ) |
139 | 144 | logs = ["docker", "logs", container] |
140 | | - return "gitlab Reconfigured!" in check_output(logs).decode() |
| 145 | + if "gitlab Reconfigured!" not in check_output(logs).decode(): |
| 146 | + return False |
| 147 | + logging.info("GitLab has finished reconfiguring.") |
| 148 | + gitlab_url = f"http://{docker_ip}:{docker_port}" |
| 149 | + for check in ("health", "readiness", "liveness"): |
| 150 | + url = f"{gitlab_url}/-/{check}" |
| 151 | + logging.info(f"Checking {check!r} endpoint at: {url}") |
| 152 | + result = requests.get(url) |
| 153 | + if result.status_code != 200: |
| 154 | + logging.info(f"{check!r} check did not return 200: {result}") |
| 155 | + return False |
| 156 | + logging.info(f"Sleeping for {SLEEP_TIME}") |
| 157 | + time.sleep(SLEEP_TIME) |
| 158 | + return True |
141 | 159 |
|
142 | 160 | return _check |
143 | 161 |
|
@@ -176,7 +194,12 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_ |
176 | 194 | docker_services.wait_until_responsive( |
177 | 195 | timeout=300, |
178 | 196 | pause=10, |
179 | | - check=lambda: check_is_alive("gitlab-test", start_time=start_time), |
| 197 | + check=lambda: check_is_alive( |
| 198 | + container="gitlab-test", |
| 199 | + start_time=start_time, |
| 200 | + docker_ip=docker_ip, |
| 201 | + docker_port=port, |
| 202 | + ), |
180 | 203 | ) |
181 | 204 | setup_time = time.perf_counter() - start_time |
182 | 205 | minutes, seconds = int(setup_time / 60), int(setup_time % 60) |
@@ -208,6 +231,7 @@ def gl(gitlab_config): |
208 | 231 | logging.info("Instantiating python-gitlab gitlab.Gitlab instance") |
209 | 232 | instance = gitlab.Gitlab.from_config("local", [gitlab_config]) |
210 | 233 |
|
| 234 | + logging.info("Reset GitLab") |
211 | 235 | reset_gitlab(instance) |
212 | 236 |
|
213 | 237 | return instance |
|
0 commit comments