Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79a10dc

Browse files
authored
harden test_dynamodb_stream_records_with_update_item (#11094)
1 parent cb71770 commit 79a10dc

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

‎tests/aws/services/dynamodb/test_dynamodb.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ def test_dynamodb_stream_records_with_update_item(
14511451
response = aws_client.dynamodbstreams.get_shard_iterator(
14521452
StreamArn=stream_arn,
14531453
ShardId=shard_id,
1454-
ShardIteratorType="LATEST",
1454+
ShardIteratorType="TRIM_HORIZON",
14551455
)
14561456
snapshot.match("get-shard-iterator", response)
14571457
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
@@ -1502,19 +1502,21 @@ def _get_item():
15021502
":v2": {"S": "value3"},
15031503
},
15041504
)
1505-
records = []
15061505

15071506
def _get_records_amount(record_amount: int):
15081507
nonlocal shard_iterator
1509-
if len(records) < record_amount:
1510-
_resp = aws_client.dynamodbstreams.get_records(ShardIterator=shard_iterator)
1511-
records.extend(_resp["Records"])
1512-
if next_shard_iterator := _resp.get("NextShardIterator"):
1513-
shard_iterator = next_shard_iterator
15141508

1515-
assert len(records) >= record_amount
1509+
all_records = []
1510+
while shard_iterator is not None:
1511+
res = aws_client.dynamodbstreams.get_records(ShardIterator=shard_iterator)
1512+
shard_iterator = res["NextShardIterator"]
1513+
all_records.extend(res["Records"])
1514+
if len(all_records) >= record_amount:
1515+
break
1516+
1517+
return all_records
15161518

1517-
retry(lambda: _get_records_amount(2), sleep=1, retries=3)
1519+
records = retry(lambda: _get_records_amount(2), sleep=1, retries=3)
15181520
snapshot.match("get-records", {"Records": records})
15191521

15201522
assert len(records) == 2

‎tests/aws/services/dynamodb/test_dynamodb.snapshot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@
12671267
}
12681268
},
12691269
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_stream_records_with_update_item": {
1270-
"recorded-date": "06-06-2024, 13:02:16",
1270+
"recorded-date": "26-06-2024, 14:28:27",
12711271
"recorded-content": {
12721272
"create-table": {
12731273
"TableDescription": {

‎tests/aws/services/dynamodb/test_dynamodb.validation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"last_validated_date": "2023-08-23T14:33:43+00:00"
4646
},
4747
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_stream_records_with_update_item": {
48-
"last_validated_date": "2024-06-06T13:02:16+00:00"
48+
"last_validated_date": "2024-06-26T14:28:26+00:00"
4949
},
5050
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_stream_stream_view_type": {
5151
"last_validated_date": "2024-05-31T14:49:56+00:00"

0 commit comments

Comments
 (0)