Retry all the ssh kitten tests on failure once

This commit is contained in:
Kovid Goyal
2024-03-26 19:45:20 +05:30
parent dd879c413a
commit aca13a619a
3 changed files with 27 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ import sys
import termios
import time
from contextlib import contextmanager
from functools import wraps
from pty import CHILD, STDIN_FILENO, STDOUT_FILENO, fork
from unittest import TestCase
@@ -174,6 +175,22 @@ def filled_history_buf(ynum=5, xnum=5, cursor=Cursor()):
return ans
def retry_on_failure(max_attempts=2, sleep_duration=2):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
for attempt in range(max_attempts):
try:
return func(*args, **kwargs)
except Exception as e:
if attempt < max_attempts - 1: # Don't sleep on the last attempt
time.sleep(sleep_duration)
else:
raise e # Re-raise the last exception
return wrapper
return decorator
class BaseTest(TestCase):
ae = TestCase.assertEqual