Skip to content

Commit

Permalink
Jump through a bunch of hoops to limit the number of times we retry d…
Browse files Browse the repository at this point in the history
…uring tests
  • Loading branch information
tomrittervg committed Sep 12, 2024
1 parent 1184cbe commit b9bd330
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ def decorate(func):
# Retry calling a function `times` times, sleeping between each tries, with an exponential backoff
# This is to be used on API calls, that are likely to fail

RETRY_TIMES = 10

def retry(_func=None, *, times=10, sleep_s=1, exp=2):

def retry(_func=None, *, sleep_s=1, exp=2):
def decorator_retry(func):
@functools.wraps(func)
def wrapper_retry(*args, **kwargs):
retries_try = times
global RETRY_TIMES
retries_try = RETRY_TIMES
sleep_duration = sleep_s
while retries_try > 0:
try:
Expand Down
3 changes: 3 additions & 0 deletions tests/functionality_all_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

sys.path.append(".")
sys.path.append("..")
import components.utilities
components.utilities.RETRY_TIMES = 2

from automation import Updatebot

from components.utilities import Struct, raise_, AssertFalse
Expand Down
3 changes: 3 additions & 0 deletions tests/functionality_commitalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

sys.path.append(".")
sys.path.append("..")
import components.utilities
components.utilities.RETRY_TIMES = 2

from automation import Updatebot

from components.utilities import Struct, NeverUseMeClass
Expand Down
4 changes: 4 additions & 0 deletions tests/functionality_two_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

sys.path.append(".")
sys.path.append("..")
import components.utilities
components.utilities.RETRY_TIMES = 2

from automation import Updatebot

from components.utilities import Struct, raise_, AssertFalse
Expand All @@ -34,6 +37,7 @@
from tests.mock_treeherder_server import MockTreeherderServerFactory, TYPE_HEALTH
from tests.database import transform_db_config_to_tmp_db


try:
from localconfig import localconfig
except ImportError:
Expand Down

0 comments on commit b9bd330

Please sign in to comment.