| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0dba899 commit a1ac9ae
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,7 +73,7 @@ jobs: | |||
| 73 | 73 | - name: Run tests | |
| 74 | 74 | env: | |
| 75 | 75 | TOXENV: ${{ matrix.toxenv }} | |
| 76 | - run: tox | ||
| 76 | + run: tox -- --override-ini='log_cli=True' | ||
| 77 | 77 | - name: Upload codecov coverage | |
| 78 | 78 | uses: codecov/codecov-action@v2 | |
| 79 | 79 | with: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,3 +90,10 @@ disable = [ | |||
| 90 | 90 | ||
| 91 | 91 | [tool.pytest.ini_options] | |
| 92 | 92 | xfail_strict = true | |
| 93 | + | ||
| 94 | + # If 'log_cli=True' the following apply | ||
| 95 | + # NOTE: If set 'log_cli_level' to 'DEBUG' will show a log of all of the HTTP requests | ||
| 96 | + # made in functional tests. | ||
| 97 | + log_cli_level = "INFO" | ||
| 98 | + log_cli_format = "%(asctime)s.%(msecs)03d [%(levelname)8s] (%(filename)s:%(funcName)s:L%(lineno)s) %(message)s" | ||
| 99 | + log_cli_date_format = "%Y-%m-%d %H:%M:%S" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + import logging | ||
| 1 | 2 | import tempfile | |
| 2 | 3 | import time | |
| 3 | 4 | import uuid | |
@@ -9,7 +10,7 @@ | |||
| 9 | 10 | import gitlab | |
| 10 | 11 | import gitlab.base | |
| 11 | 12 | ||
| 12 | - SLEEP_INTERVAL = 0.1 | ||
| 13 | + SLEEP_INTERVAL = 0.5 | ||
| 13 | 14 | TIMEOUT = 60 # seconds before timeout will occur | |
| 14 | 15 | ||
| 15 | 16 | ||
@@ -21,47 +22,69 @@ def fixture_dir(test_dir): | |||
| 21 | 22 | def reset_gitlab(gl): | |
| 22 | 23 | # previously tools/reset_gitlab.py | |
| 23 | 24 | for project in gl.projects.list(): | |
| 25 | + logging.info(f"Marking for deletion project: {project.path_with_namespace!r}") | ||
| 24 | 26 | for deploy_token in project.deploytokens.list(): | |
| 27 | + logging.info( | ||
| 28 | + f"Marking for deletion token: {deploy_token.username!r} in " | ||
| 29 | + f"project: {project.path_with_namespace!r}" | ||
| 30 | + ) | ||
| 25 | 31 | deploy_token.delete() | |
| 26 | 32 | project.delete() | |
| 27 | 33 | for group in gl.groups.list(): | |
| 34 | + logging.info(f"Marking for deletion group: {group.full_path!r}") | ||
| 28 | 35 | for deploy_token in group.deploytokens.list(): | |
| 36 | + logging.info( | ||
| 37 | + f"Marking for deletion token: {deploy_token.username!r} in " | ||
| 38 | + f"group: {group.path_with_namespace!r}" | ||
| 39 | + ) | ||
| 29 | 40 | deploy_token.delete() | |
| 30 | 41 | group.delete() | |
| 31 | 42 | for variable in gl.variables.list(): | |
| 43 | + logging.info(f"Marking for deletion variable: {variable.key!r}") | ||
| 32 | 44 | variable.delete() | |
| 33 | 45 | for user in gl.users.list(): | |
| 34 | 46 | if user.username != "root": | |
| 47 | + logging.info(f"Marking for deletion user: {user.username!r}") | ||
| 35 | 48 | user.delete(hard_delete=True) | |
| 36 | 49 | ||
| 37 | 50 | max_iterations = int(TIMEOUT / SLEEP_INTERVAL) | |
| 38 | 51 | ||
| 39 | 52 | # Ensure everything has been reset | |
| 40 | 53 | start_time = time.perf_counter() | |
| 41 | 54 | ||
| 42 | - def wait_for_maximum_list_length( | ||
| 55 | + def wait_for_list_size( | ||
| 43 | 56 | rest_manager: gitlab.base.RESTManager, description: str, max_length: int = 0 | |
| 44 | 57 | ) -> None: | |
| 45 | 58 | """Wait for the list() length to be no greater than expected maximum or fail | |
| 46 | 59 | test if timeout is exceeded""" | |
| 47 | - for _ in range(max_iterations): | ||
| 48 | - if len(rest_manager.list()) <= max_length: | ||
| 60 | + logging.info(f"Checking {description!r} has no more than {max_length} items") | ||
| 61 | + for count in range(max_iterations): | ||
| 62 | + items = rest_manager.list() | ||
| 63 | + if len(items) <= max_length: | ||
| 49 | 64 | break | |
| 65 | + logging.info( | ||
| 66 | + f"Iteration: {count} Waiting for {description!r} items to be deleted: " | ||
| 67 | + f"{[x.name for x in items]}" | ||
| 68 | + ) | ||
| 50 | 69 | time.sleep(SLEEP_INTERVAL) | |
| 51 | - assert len(rest_manager.list()) <= max_length, ( | ||
| 52 | - f"Did not delete required items for {description}. " | ||
| 53 | - f"Elapsed_time: {time.perf_counter() - start_time}" | ||
| 70 | + | ||
| 71 | + elapsed_time = time.perf_counter() - start_time | ||
| 72 | + error_message = ( | ||
| 73 | + f"More than {max_length} {description!r} items still remaining and timeout " | ||
| 74 | + f"({elapsed_time}) exceeded: {[x.name for x in items]}" | ||
| 54 | 75 | ) | |
| 76 | + if len(items) > max_length: | ||
| 77 | + logging.error(error_message) | ||
| 78 | + assert len(items) <= max_length, error_message | ||
| 55 | 79 | ||
| 56 | - wait_for_maximum_list_length(rest_manager=gl.projects, description="projects") | ||
| 57 | - wait_for_maximum_list_length(rest_manager=gl.groups, description="groups") | ||
| 58 | - wait_for_maximum_list_length(rest_manager=gl.variables, description="variables") | ||
| 59 | - wait_for_maximum_list_length( | ||
| 60 | - rest_manager=gl.users, description="users", max_length=1 | ||
| 61 | - ) | ||
| 80 | + wait_for_list_size(rest_manager=gl.projects, description="projects") | ||
| 81 | + wait_for_list_size(rest_manager=gl.groups, description="groups") | ||
| 82 | + wait_for_list_size(rest_manager=gl.variables, description="variables") | ||
| 83 | + wait_for_list_size(rest_manager=gl.users, description="users", max_length=1) | ||
| 62 | 84 | ||
| 63 | 85 | ||
| 64 | 86 | def set_token(container, fixture_dir): | |
| 87 | + logging.info("Creating API token.") | ||
| 65 | 88 | set_token_rb = fixture_dir / "set_token.rb" | |
| 66 | 89 | ||
| 67 | 90 | with open(set_token_rb, "r") as f: | |
@@ -76,6 +99,7 @@ def set_token(container, fixture_dir): | |||
| 76 | 99 | set_token_command, | |
| 77 | 100 | ] | |
| 78 | 101 | output = check_output(rails_command).decode().strip() | |
| 102 | + logging.info("Finished creating API token.") | ||
| 79 | 103 | ||
| 80 | 104 | return output | |
| 81 | 105 | ||
@@ -85,7 +109,7 @@ def pytest_report_collectionfinish(config, startdir, items): | |||
| 85 | 109 | "", | |
| 86 | 110 | "Starting GitLab container.", | |
| 87 | 111 | "Waiting for GitLab to reconfigure.", | |
| 88 | - "This may take a few minutes.", | ||
| 112 | + "This will take a few minutes.", | ||
| 89 | 113 | ] | |
| 90 | 114 | ||
| 91 | 115 | ||
@@ -129,6 +153,7 @@ def check_is_alive(): | |||
| 129 | 153 | """ | |
| 130 | 154 | ||
| 131 | 155 | def _check(container): | |
| 156 | + logging.info("Checking if GitLab container is up...") | ||
| 132 | 157 | logs = ["docker", "logs", container] | |
| 133 | 158 | return "gitlab Reconfigured!" in check_output(logs).decode() | |
| 134 | 159 | ||
@@ -144,7 +169,7 @@ def wait_for_sidekiq(gl): | |||
| 144 | 169 | """ | |
| 145 | 170 | ||
| 146 | 171 | def _wait(timeout=30, step=0.5): | |
| 147 | - for _ in range(timeout): | ||
| 172 | + for count in range(timeout): | ||
| 148 | 173 | time.sleep(step) | |
| 149 | 174 | busy = False | |
| 150 | 175 | processes = gl.sidekiq.process_metrics()["processes"] | |
@@ -153,6 +178,7 @@ def _wait(timeout=30, step=0.5): | |||
| 153 | 178 | busy = True | |
| 154 | 179 | if not busy: | |
| 155 | 180 | return True | |
| 181 | + logging.info(f"sidekiq busy {count} of {timeout}") | ||
| 156 | 182 | return False | |
| 157 | 183 | ||
| 158 | 184 | return _wait | |
@@ -163,9 +189,11 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_ | |||
| 163 | 189 | config_file = temp_dir / "python-gitlab.cfg" | |
| 164 | 190 | port = docker_services.port_for("gitlab", 80) | |
| 165 | 191 | ||
| 192 | + logging.info("Waiting for GitLab container to become ready.") | ||
| 166 | 193 | docker_services.wait_until_responsive( | |
| 167 | - timeout=200, pause=5, check=lambda: check_is_alive("gitlab-test") | ||
| 194 | + timeout=200, pause=10, check=lambda: check_is_alive("gitlab-test") | ||
| 168 | 195 | ) | |
| 196 | + logging.info("GitLab container is now ready.") | ||
| 169 | 197 | ||
| 170 | 198 | token = set_token("gitlab-test", fixture_dir=fixture_dir) | |
| 171 | 199 | ||
@@ -188,7 +216,9 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_ | |||
| 188 | 216 | def gl(gitlab_config): | |
| 189 | 217 | """Helper instance to make fixtures and asserts directly via the API.""" | |
| 190 | 218 | ||
| 219 | + logging.info("Instantiating python-gitlab gitlab.Gitlab instance") | ||
| 191 | 220 | instance = gitlab.Gitlab.from_config("local", [gitlab_config]) | |
| 221 | + | ||
| 192 | 222 | reset_gitlab(instance) | |
| 193 | 223 | ||
| 194 | 224 | return instance | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ skipsdist = True | |||
| 4 | 4 | envlist = py310,py39,py38,py37,pep8,black,twine-check,mypy,isort | |
| 5 | 5 | ||
| 6 | 6 | [testenv] | |
| 7 | - passenv = GITLAB_IMAGE GITLAB_TAG | ||
| 7 | + passenv = GITLAB_IMAGE GITLAB_TAG PY_COLORS NO_COLOR FORCE_COLOR | ||
| 8 | 8 | setenv = VIRTUAL_ENV={envdir} | |
| 9 | 9 | whitelist_externals = true | |
| 10 | 10 | usedevelop = True | |
| Back | FazBrowse Home | New Git URL |
0 commit comments