Fix flaky availability checks in docker-tests by using exponential backoff in the retry mechanism (#3499)
This commit is contained in:
parent
4a1e0ce941
commit
517257cbef
|
|
@ -42,8 +42,8 @@ MSSQL_HOST = os.getenv("MSSQL_HOST", "localhost")
|
||||||
MSSQL_PORT = int(os.getenv("MSSQL_PORT", "1433"))
|
MSSQL_PORT = int(os.getenv("MSSQL_PORT", "1433"))
|
||||||
MSSQL_USER = os.getenv("MSSQL_USER", "sa")
|
MSSQL_USER = os.getenv("MSSQL_USER", "sa")
|
||||||
MSSQL_PASSWORD = os.getenv("MSSQL_PASSWORD", "yourStrong(!)Password")
|
MSSQL_PASSWORD = os.getenv("MSSQL_PASSWORD", "yourStrong(!)Password")
|
||||||
RETRY_COUNT = 8
|
RETRY_COUNT = 5
|
||||||
RETRY_INTERVAL = 5 # Seconds
|
RETRY_INITIAL_INTERVAL = 2 # Seconds
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -56,6 +56,8 @@ def retryable(func):
|
||||||
func()
|
func()
|
||||||
return
|
return
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception as ex: # pylint: disable=broad-except
|
||||||
|
# Exponential backoff
|
||||||
|
backoff_interval = RETRY_INITIAL_INTERVAL * (2**i)
|
||||||
logger.error(
|
logger.error(
|
||||||
"waiting for %s, retry %d/%d [%s]",
|
"waiting for %s, retry %d/%d [%s]",
|
||||||
func.__name__,
|
func.__name__,
|
||||||
|
|
@ -63,7 +65,7 @@ def retryable(func):
|
||||||
RETRY_COUNT,
|
RETRY_COUNT,
|
||||||
ex,
|
ex,
|
||||||
)
|
)
|
||||||
time.sleep(RETRY_INTERVAL)
|
time.sleep(backoff_interval)
|
||||||
raise Exception(f"waiting for {func.__name__} failed")
|
raise Exception(f"waiting for {func.__name__} failed")
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue