|
2 | 2 |
|
3 | 3 | import aiobotocore
|
4 | 4 | from botocore.stub import Stubber, ANY
|
| 5 | +from botocore.exceptions import ClientError |
5 | 6 |
|
6 | 7 | from aws_xray_sdk.core import patch
|
7 | 8 | from aws_xray_sdk.core.async_context import AsyncContext
|
@@ -103,3 +104,30 @@ async def test_map_parameter_grouping(loop, recorder):
|
103 | 104 |
|
104 | 105 | aws_meta = subsegment.aws
|
105 | 106 | assert sorted(aws_meta['table_names']) == ['table1', 'table2']
|
| 107 | + |
| 108 | + |
| 109 | +async def test_context_missing_not_swallow_return(loop, recorder): |
| 110 | + xray_recorder.configure(service='test', sampling=False, |
| 111 | + context=AsyncContext(loop=loop), context_missing='LOG_ERROR') |
| 112 | + |
| 113 | + response = {'ResponseMetadata': {'RequestId': '1234', 'HTTPStatusCode': 403}} |
| 114 | + |
| 115 | + session = aiobotocore.get_session(loop=loop) |
| 116 | + async with session.create_client('dynamodb', region_name='eu-west-2') as client: |
| 117 | + with Stubber(client) as stubber: |
| 118 | + stubber.add_response('describe_table', response, {'TableName': 'mytable'}) |
| 119 | + actual_resp = await client.describe_table(TableName='mytable') |
| 120 | + |
| 121 | + assert actual_resp == response |
| 122 | + |
| 123 | + |
| 124 | +async def test_context_missing_not_suppress_exception(loop, recorder): |
| 125 | + xray_recorder.configure(service='test', sampling=False, |
| 126 | + context=AsyncContext(loop=loop), context_missing='LOG_ERROR') |
| 127 | + |
| 128 | + session = aiobotocore.get_session(loop=loop) |
| 129 | + async with session.create_client('dynamodb', region_name='eu-west-2') as client: |
| 130 | + with Stubber(client) as stubber: |
| 131 | + stubber.add_client_error('describe_table', expected_params={'TableName': ANY}) |
| 132 | + with pytest.raises(ClientError): |
| 133 | + await client.describe_table(TableName='mytable') |
0 commit comments