Skip to content

Commit 20b8404

Browse files
authored
fix: wait for CloudFormation stack deletion in pipeline bootstrap tearDown (#8744)
The test_interactive_pipeline_user_only_created_once integration test was flaky because tearDown called delete_stack without waiting for completion. On reruns or subsequent test executions, the stack could still exist (DELETE_IN_PROGRESS), causing CreateChangeSet to fail with 'Stack already exists and cannot be created again with the changeSet InitialCreation'. Add a waiter after delete_stack calls in tearDown that polls every 10s up to a 180s timeout, ensuring stacks are fully deleted before the next test begins. Timeouts are logged as warnings without failing teardown.
1 parent 1636f3e commit 20b8404

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/integration/pipeline/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,32 @@ def setUp(self):
6565
super().setUp()
6666
shutil.rmtree(os.path.join(os.getcwd(), ".aws-sam", "pipeline"), ignore_errors=True)
6767

68+
# Max time in seconds to wait for each stack deletion to complete
69+
STACK_DELETE_TIMEOUT_SECONDS = 180
70+
6871
def tearDown(self):
6972
for stack_name in self.stack_names:
7073
self._cleanup_s3_buckets(stack_name)
7174
self.cf_client.delete_stack(StackName=stack_name)
75+
self._wait_for_stack_deletions()
7276
shutil.rmtree(os.path.join(os.getcwd(), ".aws-sam", "pipeline"), ignore_errors=True)
7377
super().tearDown()
7478

79+
def _wait_for_stack_deletions(self):
80+
"""Wait for all stack deletions to complete so subsequent runs don't collide."""
81+
waiter = self.cf_client.get_waiter("stack_delete_complete")
82+
for stack_name in self.stack_names:
83+
try:
84+
waiter.wait(
85+
StackName=stack_name,
86+
WaiterConfig={
87+
"Delay": 10,
88+
"MaxAttempts": self.STACK_DELETE_TIMEOUT_SECONDS // 10,
89+
},
90+
)
91+
except botocore.exceptions.WaiterError:
92+
logging.warning("Timed out waiting for stack %s to delete", stack_name)
93+
7594
def _cleanup_s3_buckets(self, stack_name):
7695
try:
7796
stack_resources = self.cf_client.describe_stack_resources(StackName=stack_name)

0 commit comments

Comments
 (0)