e2e: Fix @retry decorator not truncating database

This commit is contained in:
Jens Langhammer 2020-10-22 14:05:29 +02:00
parent bbcf58705f
commit 39d8038533
1 changed files with 8 additions and 2 deletions

View File

@ -12,7 +12,7 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.db import connection, transaction from django.db import connection, transaction
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.shortcuts import reverse from django.shortcuts import reverse
from django.test.testcases import TestCase from django.test.testcases import TransactionTestCase
from docker import DockerClient, from_env from docker import DockerClient, from_env
from docker.models.containers import Container from docker.models.containers import Container
from selenium import webdriver from selenium import webdriver
@ -134,12 +134,14 @@ def retry(max_retires=3, exceptions=None):
if not exceptions: if not exceptions:
exceptions = [TimeoutException] exceptions = [TimeoutException]
logger = get_logger()
def retry_actual(func: Callable): def retry_actual(func: Callable):
"""Retry test multiple times""" """Retry test multiple times"""
count = 1 count = 1
@wraps(func) @wraps(func)
def wrapper(self: TestCase, *args, **kwargs): def wrapper(self: TransactionTestCase, *args, **kwargs):
"""Run test again if we're below max_retries, including tearDown and """Run test again if we're below max_retries, including tearDown and
setUp. Otherwise raise the error""" setUp. Otherwise raise the error"""
nonlocal count nonlocal count
@ -149,9 +151,13 @@ def retry(max_retires=3, exceptions=None):
except tuple(exceptions) as exc: except tuple(exceptions) as exc:
count += 1 count += 1
if count > max_retires: if count > max_retires:
logger.debug("Exceeded retry count", exc=exc, test=self)
# pylint: disable=raising-non-exception # pylint: disable=raising-non-exception
raise exc raise exc
logger.debug("Retrying on error", exc=exc, test=self)
self.tearDown() self.tearDown()
# pylint: disable=protected-access
self._post_teardown()
self.setUp() self.setUp()
return wrapper(self, *args, **kwargs) return wrapper(self, *args, **kwargs)