Skip to content

fix: use tag prefix matching to clean up samcli/lambda-* images in layer tests#8647

Merged
bnusunny merged 1 commit intodevelopfrom
fix/flaky-layer-tests
Feb 13, 2026
Merged

fix: use tag prefix matching to clean up samcli/lambda-* images in layer tests#8647
bnusunny merged 1 commit intodevelopfrom
fix/flaky-layer-tests

Conversation

@bnusunny
Copy link
Contributor

@bnusunny bnusunny commented Feb 12, 2026

Problem

The test_download_two_layers integration tests in TestLayerVersion are flaky on Docker daemon (but pass on Finch). They fail with AssertionError: '"Layer1"' != '"Layer2"', indicating stale images from previous parameterized test classes are being reused instead of rebuilt.

Changes

  • Add _cleanup_samcli_images() static method to TestLayerVersionBase that lists all Docker images and filters by samcli/lambda- tag prefix, instead of relying on exact repository name matching
  • Update tearDown and tearDownClass in TestLayerVersionBase to use the new method
  • Update TestLayerVersionThatDoNotCreateCache.tearDown with the same prefix-based cleanup

Docker's images.list(name='samcli/lambda') does exact repository matching
and won't match repositories like 'samcli/lambda-python'. This caused
stale images to persist across parameterized test classes, leading to
flaky test_download_two_layers failures where Layer2 should overwrite
Layer1 but the image was never rebuilt.

Fix by:
1. Adding _cleanup_samcli_images() that lists all images and filters by
   'samcli/lambda-' tag prefix
2. Using this method in both tearDown and tearDownClass
3. Fixing the same pattern in TestLayerVersionThatDoNotCreateCache
@bnusunny bnusunny requested a review from a team as a code owner February 12, 2026 02:32
@bnusunny bnusunny added this pull request to the merge queue Feb 13, 2026
Merged via the queue into develop with commit 463163d Feb 13, 2026
47 checks passed
bnusunny added a commit to bnusunny/aws-sam-cli that referenced this pull request Feb 13, 2026
…rm container tests

* Update notify-slack.yml to add sleep (aws#8646)

* fix: use tag prefix matching to clean up samcli/lambda-* images (aws#8647)

Docker's images.list(name='samcli/lambda') does exact repository matching
and won't match repositories like 'samcli/lambda-python'. This caused
stale images to persist across parameterized test classes, leading to
flaky test_download_two_layers failures where Layer2 should overwrite
Layer1 but the image was never rebuilt.

Fix by:
1. Adding _cleanup_samcli_images() that lists all images and filters by
   'samcli/lambda-' tag prefix
2. Using this method in both tearDown and tearDownClass
3. Fixing the same pattern in TestLayerVersionThatDoNotCreateCache

* fix: remove fallback in count_running_containers that causes flaky warm container tests

The count_running_containers method had a fallback that returned the count
of ALL SAM CLI containers when MODE env var filtering found no matches.
This caused AssertionError: 3 != 2 when stale containers from other tests
were present. Now it strictly counts only containers matching this test's
unique MODE UUID and uses exact string matching.

* fix: add AWS_DEFAULT_REGION and use -k pattern for parameterized tests

* fix: add BY_CANARY=true to enable Docker tests on CI

* fix: exclude RemoteLayers tests that need AWS credentials

---------

Co-authored-by: seshubaws <116689586+seshubaws@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants