Skip to content

Commit

Permalink
Fix the issue with Crtl+C infinite loop during the cleanup (#41)
Browse files Browse the repository at this point in the history
Fixes the bug with pressing Ctrl+C second time during test teardown
causing the teardown to start over, in an infinite loop.
Now second Ctrl+C will abort the cleanup and exit immediately. Also, it
gives a chance to press Ctrl+C second time before any cleanup started by
pausing before the cleanup for 2 seconds.
  • Loading branch information
sergiitk authored Feb 20, 2024
1 parent d2f4d9a commit b74465c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions framework/xds_k8s_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,25 @@ def handle_sigint(
self, signalnum: _SignalNum, frame: Optional[FrameType]
) -> None:
# TODO(sergiitk): move to base_testcase.BaseTestCase
logger.info("Caught Ctrl+C, cleaning up...")
self._handling_sigint = True
# Force resource cleanup by their name. Addresses the case where ctrl-c
# is pressed while waiting for the resource creation.
self.force_cleanup = True
self.tearDown()
self.tearDownClass()
if self._handling_sigint:
logger.info("Ctrl+C pressed twice, aborting the cleanup.")
else:
cleanup_delay_sec = 2
logger.info(
"Caught Ctrl+C. Cleanup will start in %d seconds."
" Press Ctrl+C again to abort.",
cleanup_delay_sec,
)
self._handling_sigint = True
# Sleep for a few seconds to allow second Ctrl-C before the cleanup.
time.sleep(cleanup_delay_sec)
# Force resource cleanup by their name. Addresses the case where
# ctrl-c is pressed while waiting for the resource creation.
self.force_cleanup = True
self.tearDown()
self.tearDownClass()

# Remove the sigint handler.
self._handling_sigint = False
if self._prev_sigint_handler is not None:
signal.signal(signal.SIGINT, self._prev_sigint_handler)
Expand Down

0 comments on commit b74465c

Please sign in to comment.