Skip to content

Commit

Permalink
Integration tests should sleep a lot less. (#2225)
Browse files Browse the repository at this point in the history
Most of the time, integration tests are sleeping and waiting to poll an endpoint. That poll time
is defined in a constant which can be overridden via env vars, but there were still places in the test
code that we not using the constant. This change fixes all those places where possible and injects
very small sleep times via environment variables in the various run_integration.sh scripts.

No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner authored Aug 15, 2024
1 parent e656930 commit 354c0a9
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 21 deletions.
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/api/rbac_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from galaxy_ng.tests.integration.utils.iqe_utils import get_ansible_config, \
get_galaxy_client, AnsibleConfigFixture
from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING
from galaxy_ng.tests.integration.utils.rbac_utils import create_local_image_container
from galaxykit.container_images import get_container, get_container_images_latest
ansible_config = get_ansible_config()
Expand Down Expand Up @@ -130,7 +131,7 @@ def wait_for_task(resp, path=None, timeout=300):
raise
else:
ready = resp.json()["state"] not in ("running", "waiting")
time.sleep(5)
time.sleep(SLEEP_SECONDS_POLLING)
return resp


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_ONETIME
from galaxy_ng.tests.integration.utils import get_client
from galaxy_ng.tests.integration.utils.iqe_utils import pull_and_tag_test_image
from galaxykit.utils import wait_for_task
Expand Down Expand Up @@ -107,7 +108,7 @@ def test_can_update_container_push(ansible_config, require_auth):
client(container_href, method="PATCH", args={"retain_repo_versions": value})

# sleep 2 seconds waiting task to finish
time.sleep(2)
time.sleep(SLEEP_SECONDS_ONETIME)
# assert the change was persisted
repo = client(container_href)
assert repo["retain_repo_versions"] == value
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/api/test_container_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_ONETIME
from galaxy_ng.tests.integration.utils import get_client
from galaxy_ng.tests.integration.utils.iqe_utils import pull_and_tag_test_image
from galaxykit.container_images import get_container
Expand Down Expand Up @@ -136,7 +137,7 @@ def test_push_and_sign_a_container(ansible_config, flags, require_auth, galaxy_c
args={"manifest_signing_service": ss_href})

# sleep 2 second2
time.sleep(2)
time.sleep(SLEEP_SECONDS_ONETIME)

repo = client(container_href)
latest_version_href = repo["latest_version_href"]
Expand Down
5 changes: 3 additions & 2 deletions galaxy_ng/tests/integration/api/test_namespace_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from galaxykit.repositories import search_collection
from galaxykit.users import get_me

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_ONETIME
from ..utils.iqe_utils import is_stage_environment
from ..utils.repo_management_utils import upload_new_artifact
from ..utils.tasks import wait_for_all_tasks_gk, wait_for_namespace_tasks_gk
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_namespace_edit_logo(galaxy_client):
}
my_namespace = gc.post("_ui/v1/my-namespaces/", body=payload)
assert my_namespace["avatar_url"] == ''
sleep(60)
sleep(SLEEP_SECONDS_ONETIME)
wait_for_all_tasks_gk(gc)

namespaces = gc.get('_ui/v1/my-namespaces/')
Expand All @@ -169,7 +170,7 @@ def test_namespace_edit_logo(galaxy_client):
"avatar_url": "https://avatars.githubusercontent.com/u/1869705?v=4"
}
gc.put(f"_ui/v1/my-namespaces/{name}/", body=payload)
sleep(60)
sleep(SLEEP_SECONDS_ONETIME)
wait_for_all_tasks_gk(gc)
updated_namespace = gc.get(f'_ui/v1/my-namespaces/{name}/')
assert updated_namespace["avatar_url"] != ""
Expand Down
5 changes: 3 additions & 2 deletions galaxy_ng/tests/integration/api/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import time

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING
from galaxy_ng.tests.integration.utils.iqe_utils import is_ocp_env
from galaxy_ng.tests.integration.utils.rbac_utils import upload_test_artifact

Expand Down Expand Up @@ -126,7 +127,7 @@ def test_move_cv_endpoint(self, galaxy_client):
break
except Exception as e:
print(e)
time.sleep(5)
time.sleep(SLEEP_SECONDS_POLLING)

if repo_pulp_href_2 is None:
raise Exception("failed to create repo and dist")
Expand All @@ -148,7 +149,7 @@ def test_move_cv_endpoint(self, galaxy_client):
break
except Exception as e:
print(e)
time.sleep(5)
time.sleep(SLEEP_SECONDS_POLLING)

# verify cv is only in destination repo
_, results = search_collection_endpoint(gc_admin, name=artifact.name)
Expand Down
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/api/test_upload_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
create_test_namespace
from ..utils.tools import generate_random_string
from ..utils.iqe_utils import aap_gateway
from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING


@pytest.mark.min_hub_version("4.8dev")
Expand Down Expand Up @@ -64,6 +65,6 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client):
)
if matches == len(artifacts):
break
time.sleep(10)
time.sleep(SLEEP_SECONDS_POLLING)

assert matches == len(artifacts)
5 changes: 3 additions & 2 deletions galaxy_ng/tests/integration/community/test_community_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from urllib.parse import urlparse

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING
from ..utils import (
ansible_galaxy,
build_collection,
Expand Down Expand Up @@ -283,7 +284,7 @@ def test_social_auth_delete_collection(ansible_config):
)
if exists_resp.status_code == 200:
break
time.sleep(5)
time.sleep(SLEEP_SECONDS_POLLING)
assert exists_resp.status_code == 200

del_resp = client.delete(
Expand Down Expand Up @@ -340,7 +341,7 @@ def test_social_auth_deprecate_collection(ansible_config):
)
if exists_resp.status_code == 200:
break
time.sleep(5)
time.sleep(SLEEP_SECONDS_POLLING)
assert exists_resp.status_code == 200

dep_resp = client.patch(
Expand Down
10 changes: 5 additions & 5 deletions galaxy_ng/tests/integration/utils/iqe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from pkg_resources import parse_version

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING
from galaxy_ng.tests.integration.constants import POLLING_MAX_ATTEMPTS
from galaxy_ng.tests.integration.constants import GALAXY_STAGE_ANSIBLE_PROFILES, \
EPHEMERAL_PROFILES, PROFILES, CREDENTIALS, SYNC_PROFILES, DEPLOYED_PAH_PROFILES
from galaxy_ng.tests.integration.utils import get_client
Expand Down Expand Up @@ -722,17 +724,15 @@ def require_signature_for_approval():
ansible_config = get_ansible_config()
galaxy_client = get_galaxy_client(ansible_config)
gc = galaxy_client("admin")
max_attempts = 5
delay = 3
# we need retries because in ephemeral env we get 502 sometimes
for attempt in range(1, max_attempts + 1):
for attempt in range(1, POLLING_MAX_ATTEMPTS + 1):
try:
settings = gc.get_settings()
return settings.get("GALAXY_REQUIRE_SIGNATURE_FOR_APPROVAL")
except JSONDecodeError as e:
if attempt == max_attempts:
if attempt == POLLING_MAX_ATTEMPTS:
raise e
time.sleep(delay)
time.sleep(SLEEP_SECONDS_POLLING)


def sign_collection_on_demand(client, signing_service, repo, ns, collection_name,
Expand Down
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/utils/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import yaml

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING
from galaxykit.users import delete_user as delete_user_gk
from .client_ansible_lib import get_client
from .namespaces import cleanup_namespace, cleanup_namespace_gk
Expand All @@ -32,7 +33,7 @@ def wait_for_v1_task(task_id=None, resp=None, api_client=None, check=True):
state = task_resp['results'][0]['state']
if state != 'RUNNING':
break
time.sleep(.5)
time.sleep(SLEEP_SECONDS_POLLING)

if check:
assert state == 'SUCCESS'
Expand Down
6 changes: 3 additions & 3 deletions galaxy_ng/tests/integration/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def wait_for_all_tasks(client, timeout=300):

ready = running_count == 0 and waiting_count == 0

time.sleep(1)
time.sleep(SLEEP_SECONDS_POLLING)


def wait_for_all_tasks_gk(gc, timeout=300):
Expand All @@ -42,7 +42,7 @@ def wait_for_all_tasks_gk(gc, timeout=300):
running_count = gc.get("pulp/api/v3/tasks/?state=running")["count"]
waiting_count = gc.get("pulp/api/v3/tasks/?state=waiting")["count"]
ready = running_count == 0 and waiting_count == 0
time.sleep(1)
time.sleep(SLEEP_SECONDS_POLLING)


def wait_for_task(api_client, resp, task_id=None, timeout=6000, raise_on_error=False):
Expand Down Expand Up @@ -100,7 +100,7 @@ def wait_for_namespace_tasks_gk(gc, timeout=300):
running_count = gc.get("pulp/api/v3/tasks/?state=running&name__contains=namespace")["count"]
waiting_count = gc.get("pulp/api/v3/tasks/?state=waiting&name__contains=namespace")["count"]
ready = running_count == 0 and waiting_count == 0
time.sleep(1)
time.sleep(SLEEP_SECONDS_POLLING)


class TaskFailed(Exception):
Expand Down
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from galaxykit.utils import GalaxyClientError
from .errors import CapturingGalaxyError, TaskWaitingTimeout
from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING


def test_url_safe_join():
Expand Down Expand Up @@ -126,7 +127,7 @@ def wait_for_url(api_client, url, timeout_sec=6000):
except (GalaxyError, CapturingGalaxyError, GalaxyClientError) as e:
if "404" not in str(e):
raise
time.sleep(0.5)
time.sleep(SLEEP_SECONDS_POLLING)
else:
ready = True
return res
7 changes: 6 additions & 1 deletion profiles/base/run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ cd /src/galaxy_ng/

# echo $MARKS


export GALAXYKIT_SLEEP_SECONDS_POLLING=.5
export GALAXYKIT_SLEEP_SECONDS_ONETIME=.5
export GALAXYKIT_POLLING_MAX_ATTEMPTS=50
export GALAXY_SLEEP_SECONDS_POLLING=.5
export GALAXY_SLEEP_SECONDS_ONETIME=.5
export GALAXY_POLLING_MAX_ATTEMPTS=50

# TODO: fix marks
set -x
Expand Down
7 changes: 7 additions & 0 deletions profiles/dab_jwt/run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export JWT_PROXY=true
export AAP_GATEWAY=true
export GW_ROOT_URL=http://jwtproxy:8080

export GALAXYKIT_SLEEP_SECONDS_POLLING=.5
export GALAXYKIT_SLEEP_SECONDS_ONETIME=.5
export GALAXYKIT_POLLING_MAX_ATTEMPTS=50
export GALAXY_SLEEP_SECONDS_POLLING=.5
export GALAXY_SLEEP_SECONDS_ONETIME=.5
export GALAXY_POLLING_MAX_ATTEMPTS=50

#$VENVPATH/bin/pytest -v -r sx --color=yes "$@" galaxy_ng/tests/integration/dab
$VENVPATH/bin/pytest -v -r sx --color=yes -m "$HUB_TEST_MARKS" "$@" galaxy_ng/tests/integration
RC=$?
Expand Down

0 comments on commit 354c0a9

Please sign in to comment.