Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
test: isolate three tests from other workers and AUTH=true (#2201)
iot-rocket74ec8593e137
diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 5b2472de..84139cf6 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -1110,7 +1110,7 @@ def test_cfn_iot_certificate_refuses_property_combinations(cfn, iot_client, prop"""Each certificate mode takes one exact set of sources; anything elsefails the resource with AWS's message and creates no certificate."""pytest.importorskip("cryptography")- from ministack.core.x509_utils import generate_ca, sign_leaf_certificate+ from ministack.core.x509_utils import certificate_common_name, generate_ca, sign_leaf_certificateuid = _uuid_mod.uuid4().hex[:8]stack = f"cfn-cert-bad-{uid}"@@ -1119,12 +1119,28 @@ def test_cfn_iot_certificate_refuses_property_combinations(cfn, iot_client, prop"csr": _cfn_iot_csr(uid)[0]}props = {k: values.get(v, v) for k, v in props.items()}before = {c["certificateId"] for c in iot_client.list_certificates()["certificates"]}++ def created():+ """New certificates whose subject carries this test's uid; other workers add and delete theirs meanwhile."""+ ids = []+ for cert in iot_client.list_certificates()["certificates"]:+ if cert["certificateId"] in before:+ continue+ try:+ pem = iot_client.describe_certificate(+ certificateId=cert["certificateId"])["certificateDescription"]["certificatePem"]+ except iot_client.exceptions.ResourceNotFoundException:+ continue+ if uid in (certificate_common_name(pem) or ""):+ ids.append(cert["certificateId"])+ return ids+try:cfn.create_stack(StackName=stack, TemplateBody=json.dumps({"Resources": {"Cert": {"Type": "AWS::IoT::Certificate", "Properties": {**props, "Status": "ACTIVE"}}}}))assert _wait_stack(cfn, stack)["StackStatus"] == "ROLLBACK_COMPLETE"assert _cfn_iot_failure(cfn, stack, "Cert", "CREATE_FAILED") == reason- assert {c["certificateId"] for c in iot_client.list_certificates()["certificates"]} == before+ assert created() == []finally:_delete_cfn_test_stack(cfn, stack)diff --git a/tests/test_iot_data.py b/tests/test_iot_data.pyindex e9ab8cf9..5d12cca4 100644--- a/tests/test_iot_data.py+++ b/tests/test_iot_data.py@@ -501,7 +501,8 @@ async def _ws_subscribe_and_collect(ws_url: str, topic: str, ready_event: threading.Event, received: list, stop: threading.Event):async with websockets.connect(ws_url, subprotocols=["mqtt"]) as ws:- await ws.send(_make_connect("test-client"))+ # Unique: a parallel worker connecting with the same client id would take this session over.+ await ws.send(_make_connect(_unique("test-client")))# Wait for CONNACKawait asyncio.wait_for(ws.recv(), timeout=_WS_HANDSHAKE_TIMEOUT)# Subscribediff --git a/tests/test_lambda.py b/tests/test_lambda.pyindex 2b45421a..ed4043a4 100644--- a/tests/test_lambda.py+++ b/tests/test_lambda.py@@ -81,6 +81,15 @@ _LAMBDA_CODE_V2 = 'def handler(event, context):\n return {"statusCode": 200,_LAMBDA_ROLE = "arn:aws:iam::000000000000:role/lambda-role"+[email protected](autouse=True)+def _lambda_role(iam):+ """The role ``_LAMBDA_ROLE`` names, per test since some reset the server: AUTH=true needs it to exist."""+ with contextlib.suppress(iam.exceptions.EntityAlreadyExistsException):+ iam.create_role(RoleName="lambda-role", AssumeRolePolicyDocument=json.dumps({"Statement": [{+ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}))++_NODE_CODE = ("exports.handler = async (event, context) => {"" return { statusCode: 200, body: JSON.stringify({ hello: event.name || 'world' }) }; };"