|
4 | 4 | from aws_xray_sdk.core.models.segment import Segment
|
5 | 5 | from aws_xray_sdk.core.models.subsegment import Subsegment
|
6 | 6 | from aws_xray_sdk.core.models import http
|
7 |
| -from aws_xray_sdk.core.models import throwable |
8 | 7 | from aws_xray_sdk.core.exceptions.exceptions import SegmentNameMissingException
|
9 | 8 | from aws_xray_sdk.core.exceptions.exceptions import SegmentNotFoundException
|
10 | 9 | from aws_xray_sdk.core.exceptions.exceptions import AlreadyEndedException
|
@@ -215,4 +214,46 @@ def test_add_exception():
|
215 | 214 | assert expected_stack == exception.stack
|
216 | 215 |
|
217 | 216 |
|
| 217 | +def test_add_exception_referencing(): |
| 218 | + segment = Segment('seg') |
| 219 | + subseg = Subsegment('subseg') |
| 220 | + exception = Exception("testException") |
| 221 | + stack = [['path', 'line', 'label']] |
| 222 | + subseg.add_exception(exception=exception, stack=stack) |
| 223 | + segment.add_exception(exception=exception, stack=stack) |
| 224 | + subseg.close() |
| 225 | + segment.close() |
| 226 | + |
| 227 | + seg_cause = segment.cause |
| 228 | + subseg_cause = subseg.cause |
| 229 | + |
| 230 | + assert isinstance(subseg_cause, dict) |
| 231 | + assert isinstance(seg_cause, str) |
| 232 | + assert seg_cause == subseg_cause['exceptions'][0].id |
| 233 | + |
| 234 | + |
| 235 | +def test_add_exception_cause_resetting(): |
| 236 | + segment = Segment('seg') |
| 237 | + subseg = Subsegment('subseg') |
| 238 | + exception = Exception("testException") |
| 239 | + stack = [['path', 'line', 'label']] |
| 240 | + subseg.add_exception(exception=exception, stack=stack) |
| 241 | + segment.add_exception(exception=exception, stack=stack) |
| 242 | + |
| 243 | + segment.add_exception(exception=Exception("newException")) |
| 244 | + subseg.close() |
| 245 | + segment.close() |
| 246 | + |
| 247 | + seg_cause = segment.cause |
| 248 | + assert isinstance(seg_cause, dict) |
| 249 | + assert 'newException' == seg_cause['exceptons'][0].message |
| 250 | + |
| 251 | + |
| 252 | +def test_add_exception_appending_exceptions(): |
| 253 | + segment = Segment('seg') |
| 254 | + segment.add_exception(exception=Exception("testException")) |
| 255 | + segment.add_exception(exception=Exception("newException")) |
| 256 | + segment.close() |
218 | 257 |
|
| 258 | + assert isinstance(segment.cause, dict) |
| 259 | + assert len(segment.cause['exceptions']) == 2 |
0 commit comments