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 6, 2024
1 parent 57f296d commit 7d2f4f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions apis/phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
import platform

from components.utilities import retry
from components.utilities import retry, RETRY_TIMES
from components.logging import logEntryExit, LogLevel
from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider

Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self, config):
self.url = config['url']

@logEntryExit
@retry
@retry(times=RETRY_TIMES)
def submit_patches(self, bug_id, has_patches):
phab_revisions = []

Expand Down Expand Up @@ -89,7 +89,7 @@ def submit_to_phabricator(rev_id):
return phab_revisions

@logEntryExit
@retry
@retry(times=RETRY_TIMES)
def set_reviewer(self, phab_revision, phab_username):
# We have to call a different API endpoint if this is a review group
if phab_username[0] == "#":
Expand Down Expand Up @@ -123,7 +123,7 @@ def set_reviewer(self, phab_revision, phab_username):
raise Exception("Got an error from phabricator when trying to set reviewers to %s (%s) for %s: %s" % (phab_username, phid, phab_revision, result))

@logEntryExit
@retry
@retry(times=RETRY_TIMES)
def abandon(self, phab_revision):
cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"abandon", "value":true}],"objectIdentifier": "%s"}""" % phab_revision)
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url)
Expand Down
4 changes: 2 additions & 2 deletions apis/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections import defaultdict
from urllib.parse import quote_plus

from components.utilities import retry, Struct, merge_dictionaries, PUSH_HEALTH_IGNORED_DICTS, PUSH_HEALTH_IGNORED_KEYS
from components.utilities import retry, RETRY_TIMES, Struct, merge_dictionaries, PUSH_HEALTH_IGNORED_DICTS, PUSH_HEALTH_IGNORED_KEYS
from components.logging import logEntryExit, logEntryExitNoArgs, LogLevel
from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider

Expand Down Expand Up @@ -149,7 +149,7 @@ def _vcs_setup(self):
self._vcs_setup_initialized = True

@logEntryExit
@retry
@retry(times=RETRY_TIMES)
def submit_to_try(self, library, platform_filter, recursed=0):
self._vcs_setup()
if not platform_filter:
Expand Down
4 changes: 2 additions & 2 deletions components/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ 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


def retry(_func=None, *, times=10, sleep_s=1, exp=2):
RETRY_TIMES=10
def retry(_func=None, *, times=RETRY_TIMES, sleep_s=1, exp=2):
def decorator_retry(func):
@functools.wraps(func)
def wrapper_retry(*args, **kwargs):
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 7d2f4f9

Please sign in to comment.