Skip to content

Commit

Permalink
fix(ci): Fix flaky tests related to stubber out of order expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
LaikaN57 committed Feb 12, 2025
1 parent 217b6e0 commit 2d73c19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions kingpin/actors/aws/test/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,23 @@ def test_get_entity_policies_500(self):

@testing.gen_test
def test_get_entity_policies_400(self):
# Next, what if the entity doesn't exist at all?
self.iam_stubber = Stubber(self.actor.iam_conn)
self.iam_stubber.add_client_error("list_user_policies", "400", "NoSuchEntity")
self.iam_stubber.activate()
ret = yield self.actor._get_entity_policies("test")
self.assertEqual(ret, {})

@testing.gen_test
def test_get_entities_other_500(self):
self.iam_stubber.add_client_error("list_user_policies", "400", "NoSuchEntity")
self.iam_stubber = Stubber(self.actor.iam_conn)
self.iam_stubber.add_response(
# API Call
"list_user_policies",
# Response
{"PolicyNames": ["test1", "test2", "test3"]},
# Use one policy here so we do not have to deal with extra calls
# and multiple Stubber responses.
{"PolicyNames": ["test1"]},
# Call Params
{"UserName": "test"},
)

self.iam_stubber.add_client_error("get_user_policy", "500", "SomeError")
self.iam_stubber.activate()
with self.assertRaises(exceptions.RecoverableActorFailure):
Expand Down Expand Up @@ -142,7 +139,11 @@ def test_get_entity_policies(self):
# Response
{"UserName": "test", "PolicyName": pol, "PolicyDocument": policy_str},
# Call Params
{"UserName": "test", "PolicyName": pol},
# Disable expected parameters because calls to
# api_call(self.get_entity_policy, [...]) can come in out of order but boto3 Subber
# expects them to be in order if you use this parameter. We do our own checks below
# to ensure we have all the data we expected.
# {"UserName": "test", "PolicyName": pol},
)

# Finally, make the call and see if we get all the policies
Expand Down
2 changes: 1 addition & 1 deletion kingpin/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Kingpin version number. You must bump this when creating a new release."""

__version__ = "4.0.0"
__version__ = "4.0.1"

0 comments on commit 2d73c19

Please sign in to comment.