Skip to content

Commit

Permalink
[PSM Interop] URL Map graceful teardown (#33090)
Browse files Browse the repository at this point in the history
Similar to what we already do in other test suites:

- Try cleaning up resources three times.
- If unsuccessful, don't fail the test and just log the error. The
cleanup script should be the one to deal with this.

ref b/282081851
  • Loading branch information
sergiitk committed May 12, 2023
1 parent 9760ce9 commit 0d678a9
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
HostRule = xds_url_map_test_resources.HostRule
PathMatcher = xds_url_map_test_resources.PathMatcher
JsonType = Any
_timedelta = datetime.timedelta

# ProtoBuf translatable RpcType enums
RpcTypeUnaryCall = 'UNARY_CALL'
Expand Down Expand Up @@ -362,11 +363,26 @@ def setUpClass(cls):

@classmethod
def cleanupAfterTests(cls):
logging.info('----- Doing cleanup after %s -----', cls.__name__)
cls.test_client_runner.cleanup(force=True, force_namespace=True)
logging.info('----- TestCase %s teardown -----', cls.__name__)
retryer = retryers.constant_retryer(wait_fixed=_timedelta(seconds=10),
attempts=3,
log_level=logging.INFO)
cls.finished_test_cases.add(cls.__name__)
if cls.finished_test_cases == cls.test_case_names:
# Tear down the GCP resource after all tests finished
# Whether to clean up shared pre-provisioned infrastructure too.
# We only do it after all tests are finished.
cleanup_all = cls.finished_test_cases == cls.test_case_names

# Graceful cleanup: try three times, and don't fail the test on
# a cleanup failure.
try:
retryer(cls._cleanup, cleanup_all)
except retryers.RetryError:
logging.exception('Got error during teardown')

@classmethod
def _cleanup(cls, cleanup_all: bool = False):
cls.test_client_runner.cleanup(force=True, force_namespace=True)
if cleanup_all:
GcpResourceManager().cleanup()

def _fetch_and_check_xds_config(self):
Expand Down

0 comments on commit 0d678a9

Please sign in to comment.