aws-samples/aws-serverless-ecommerce-platform

FAILED tests/integ/test_events.py::test_table_update - AssertionError

fintechee opened this issue · 0 comments

Hi,

I met this error while running "make all".
"sless_ec" is the root folder.


[*] tests-integ orders
make[3]: Entering directory '/home/ubuntu/sless_ec/orders'
============================= test session starts ==============================
platform linux -- Python 3.9.7, pytest-5.4.3, py-1.11.0, pluggy-0.13.1
rootdir: /home/ubuntu/sless_ec/warehouse
plugins: requests-mock-1.9.3, cov-2.8.1
collected 2 items

tests/integ/test_events.py F [ 50%]
tests/integ/test_on_order_events.py . [100%]

=================================== FAILURES ===================================
______________________________ test_table_update _______________________________

table_name = 'ecommerce-dev-warehouse-Table-1NKQ7PBKTM1VH'
metadata = {'modifiedDate': '2022-04-07T03:24:49.534936', 'orderId': '372337dc-0acf-4aba-9882-e600ec498b7e', 'productId' : '__metadata', 'status': 'COMPLETED'}
products = [{'name': 'PRODUCT_NAME', 'orderId': '372337dc-0acf-4aba-9882-e600ec498b7e', 'package': {'height': 50, 'lengt h': 100, 'weight': 1000, 'width': 200}, 'price': 500, ...}]
listener = <function listener.._listener at 0x7f287b52e700>

def test_table_update(table_name, metadata, products, listener):
    """
    Test that the TableUpdate function reacts to changes to DynamoDB and sends
    events to EventBridge
    """

    metadata = copy.deepcopy(metadata)

    # Create packaging request in DynamoDB
    table = boto3.resource("dynamodb").Table(table_name) # pylint: disable=no-member

    with table.batch_writer() as batch:
        for product in products:
            batch.put_item(Item=product)
        batch.put_item(Item=metadata)

    # Mark the packaging as completed
    metadata["status"] = "COMPLETED"


    # Listen for messages on EventBridge
  listener(
        "ecommerce.warehouse",
        lambda: table.put_item(Item=metadata),
        lambda m: metadata["orderId"] in m["resources"] and m["detail-type"] == "PackageCreated"
    )

tests/integ/test_events.py:84:


../shared/tests/integ/fixtures.py:120: in _listener
return asyncio.run(_listen())
../../.pyenv/versions/3.9.7/lib/python3.9/asyncio/runners.py:44: in run
return loop.run_until_complete(main)
../../.pyenv/versions/3.9.7/lib/python3.9/asyncio/base_events.py:642: in run_until_complete
return future.result()


async def _listen() -> List[dict]:
    # Generate SigV4 headers
    headers = signed_url_headers(listener_api_url)
    # Connects to API
    async with websockets.connect(listener_api_url, extra_headers=headers) as websocket:
        # Send to which service we are subscribing
        await websocket.send(
            json.dumps({"action": "register", "serviceName": service_name})
        )

        # Run the function that will produce messages
        gen_function()

        # Listen to messages through the WebSockets API
        found = False
        messages = []
        # Since asyncio.wait_for timeout parameter takes an integer, we need to
        # calculate the value. For this, we calculate the datetime until we want to
        # wait in the worst case, then calculate the timeout integer value based on
        # that.
        timeout = datetime.datetime.utcnow() + datetime.timedelta(seconds=wait_time)
        while datetime.datetime.utcnow() < timeout:
            try:
                message = json.loads(await asyncio.wait_for(
                    websocket.recv(),
                    timeout=(timeout - datetime.datetime.utcnow()).total_seconds()
                ))
                print(message)
                messages.append(message)
                # Run the user-provided test
                if test_function is not None and test_function(message):
                    found = True
                    break
            except asyncio.exceptions.TimeoutError:
                # Timeout exceeded
                break

        if test_function is not None:
          assert found == True

E AssertionError

../shared/tests/integ/fixtures.py:116: AssertionError
---- generated xml file: /home/ubuntu/sless_ec/reports/warehouse-integ.xml -----
=========================== short test summary info ============================
FAILED tests/integ/test_events.py::test_table_update - AssertionError
========================= 1 failed, 1 passed in 37.07s =========================
make[3]: *** [Makefile:37: tests-integ] Error 1
make[3]: Leaving directory '/home/ubuntu/sless_ec/warehouse'
make[2]: *** [Makefile:103: tests-integ-warehouse] Error 2
make[2]: Leaving directory '/home/ubuntu/sless_ec'
make[1]: *** [Makefile:34: all-warehouse] Error 2
make[1]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/home/ubuntu/sless_ec/orders'
make[2]: Leaving directory '/home/ubuntu/sless_ec'
make[1]: Leaving directory '/home/ubuntu/sless_ec'
make: *** [Makefile:24: all] Error 1

I'm completely newbie to this repo.
I want to know what caused the failure, how to solve it.

Many thanks.