fix(test): another attempt on flaky tests fixes
- cleanup DB calls for flaky tests
This commit is contained in:
parent
bf9cd8455f
commit
cafdf00501
4 changed files with 24 additions and 18 deletions
|
|
@ -2693,6 +2693,7 @@ class Repository(Base, BaseModel):
|
||||||
|
|
||||||
empty_date = datetime.datetime.fromtimestamp(0)
|
empty_date = datetime.datetime.fromtimestamp(0)
|
||||||
repo_commit_count = 0
|
repo_commit_count = 0
|
||||||
|
repo_name = self.repo_name
|
||||||
|
|
||||||
if cs_cache is None:
|
if cs_cache is None:
|
||||||
# use no-cache version here
|
# use no-cache version here
|
||||||
|
|
@ -2767,7 +2768,7 @@ class Repository(Base, BaseModel):
|
||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
"updated repo `%s` with new commit cache %s, and last update_date: %s",
|
"updated repo `%s` with new commit cache %s, and last update_date: %s",
|
||||||
self.repo_name,
|
repo_name,
|
||||||
cs_cache,
|
cs_cache,
|
||||||
_date_latest,
|
_date_latest,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
18
rhodecode/tests/fixtures/fixture_utils.py
vendored
18
rhodecode/tests/fixtures/fixture_utils.py
vendored
|
|
@ -26,13 +26,14 @@ import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
import string
|
||||||
|
import random
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
|
|
||||||
import dateutil.tz
|
import dateutil.tz
|
||||||
import logging
|
import logging
|
||||||
import functools
|
import functools
|
||||||
import textwrap
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pyramid.testing
|
import pyramid.testing
|
||||||
|
|
@ -1131,7 +1132,7 @@ def user_util(request, db_connection):
|
||||||
# TODO: johbo: Split this up into utilities per domain or something similar
|
# TODO: johbo: Split this up into utilities per domain or something similar
|
||||||
class UserUtility(object):
|
class UserUtility(object):
|
||||||
def __init__(self, test_name="test"):
|
def __init__(self, test_name="test"):
|
||||||
self._test_name = self._sanitize_name(test_name)
|
self._test_name = self._sanitize_name(test_name, random_suffix=True)
|
||||||
self.fixture = Fixture()
|
self.fixture = Fixture()
|
||||||
self.repo_group_ids = []
|
self.repo_group_ids = []
|
||||||
self.repos_ids = []
|
self.repos_ids = []
|
||||||
|
|
@ -1145,20 +1146,25 @@ class UserUtility(object):
|
||||||
self.user_group_user_group_permission_ids = []
|
self.user_group_user_group_permission_ids = []
|
||||||
self.user_permissions = []
|
self.user_permissions = []
|
||||||
|
|
||||||
def _sanitize_name(self, name):
|
def _sanitize_name(self, name, random_suffix=True):
|
||||||
for char in ["[", "]"]:
|
for char in ["[", "]"]:
|
||||||
name = name.replace(char, "_")
|
name = name.replace(char, "-").replace("_", "-").replace(".", "-")
|
||||||
|
if random_suffix:
|
||||||
|
length = 4
|
||||||
|
letters = string.ascii_lowercase
|
||||||
|
random_suffix = "".join(random.choice(letters) for i in range(length)).capitalize()
|
||||||
|
name = random_suffix + name
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def create_repo_group(self, owner=TEST_USER_ADMIN_LOGIN, auto_cleanup=True):
|
def create_repo_group(self, owner=TEST_USER_ADMIN_LOGIN, auto_cleanup=True):
|
||||||
group_name = f"{self._test_name}_repogroup_{len(self.repo_group_ids)}"
|
group_name = f"{self._test_name}-repogroup-{len(self.repo_group_ids)}"
|
||||||
repo_group = self.fixture.create_repo_group(group_name, cur_user=owner)
|
repo_group = self.fixture.create_repo_group(group_name, cur_user=owner)
|
||||||
if auto_cleanup:
|
if auto_cleanup:
|
||||||
self.repo_group_ids.append(repo_group.group_id)
|
self.repo_group_ids.append(repo_group.group_id)
|
||||||
return repo_group
|
return repo_group
|
||||||
|
|
||||||
def create_repo(self, owner=TEST_USER_ADMIN_LOGIN, parent=None, auto_cleanup=True, repo_type="hg", bare=False):
|
def create_repo(self, owner=TEST_USER_ADMIN_LOGIN, parent=None, auto_cleanup=True, repo_type="hg", bare=False):
|
||||||
repo_name = f"{self._test_name}_repository_{len(self.repos_ids)}"
|
repo_name = f"{self._test_name}-repository-{len(self.repos_ids)}"
|
||||||
|
|
||||||
repository = self.fixture.create_repo(
|
repository = self.fixture.create_repo(
|
||||||
repo_name, cur_user=owner, repo_group=parent, repo_type=repo_type, bare=bare
|
repo_name, cur_user=owner, repo_group=parent, repo_type=repo_type, bare=bare
|
||||||
|
|
|
||||||
|
|
@ -379,12 +379,16 @@ def branch_permission_setter(request):
|
||||||
def cleanup():
|
def cleanup():
|
||||||
# Clean up ALL created rules and permissions, not just the last ones
|
# Clean up ALL created rules and permissions, not just the last ones
|
||||||
# Critical for PostgreSQL where orphaned rows cause duplicate results
|
# Critical for PostgreSQL where orphaned rows cause duplicate results
|
||||||
for rule in created_rules:
|
if created_rules:
|
||||||
Session().delete(rule)
|
for rule in created_rules:
|
||||||
Session().commit()
|
Session().delete(rule)
|
||||||
|
|
||||||
for write_perm in created_write_perms:
|
Session().commit()
|
||||||
Session().delete(write_perm)
|
|
||||||
Session().commit()
|
if created_write_perms:
|
||||||
|
for write_perm in created_write_perms:
|
||||||
|
Session().delete(write_perm)
|
||||||
|
|
||||||
|
Session().commit()
|
||||||
|
|
||||||
return _branch_permissions_setter
|
return _branch_permissions_setter
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,6 @@ class TestVCSOperations(object):
|
||||||
branch_permission_setter(repo_name, username, permission=branch_perm)
|
branch_permission_setter(repo_name, username, permission=branch_perm)
|
||||||
|
|
||||||
clone_url = rcstack.repo_clone_url(repo.repo_name, user=username, passwd=password)
|
clone_url = rcstack.repo_clone_url(repo.repo_name, user=username, passwd=password)
|
||||||
# Give VCSServer time to initialize the empty Mercurial repository
|
|
||||||
# Empty hg repos (unlike git bare repos) need a moment to be fully indexed
|
|
||||||
# This prevents intermittent "repository is unrelated" errors
|
|
||||||
time.sleep(0.2)
|
|
||||||
repo.scm_instance(cache=False) # Force load in VCSServer
|
|
||||||
|
|
||||||
Command(os.path.dirname(tmpdir.strpath)).execute("hg clone", clone_url, tmpdir.strpath)
|
Command(os.path.dirname(tmpdir.strpath)).execute("hg clone", clone_url, tmpdir.strpath)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue