Skip to content

Commit ff6e3c4

Browse files
add test for try catch on checkpoint exception
1 parent 34b9f45 commit ff6e3c4

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/test_dsm.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,35 @@ def test_sqs_multiple_records_process_each_record(self):
141141
self.assertEqual(pathway_ctx, expected_contexts[i])
142142

143143
def test_set_context_exception_handled(self):
144+
"""Test that exceptions in set_consume_checkpoint are properly handled"""
145+
self.mock_get_dsm_context_from_sqs_lambda.return_value = {
146+
"dd-pathway-ctx": "test-context"
147+
}
148+
149+
self.mock_set_consume_checkpoint.side_effect = Exception("Checkpoint error")
150+
151+
event = {
152+
"Records": [
153+
{
154+
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:my-queue",
155+
"body": "Test message",
156+
"messageAttributes": {
157+
"_datadog": {
158+
"stringValue": '{"dd-pathway-ctx": "test-context"}',
159+
"dataType": "String",
160+
}
161+
},
162+
}
163+
]
164+
}
165+
166+
_dsm_set_sqs_context(event)
167+
168+
self.mock_logger.error.assert_called_once_with(
169+
"Unable to set dsm context: Checkpoint error"
170+
)
171+
172+
def test_get_context_exception_handled(self):
144173
"""Test that exceptions in _get_dsm_context_from_sqs_lambda are properly handled"""
145174
self.mock_get_dsm_context_from_sqs_lambda.side_effect = Exception(
146175
"JSON parsing error"
@@ -153,7 +182,7 @@ def test_set_context_exception_handled(self):
153182
"body": "Test message",
154183
"messageAttributes": {
155184
"_datadog": {
156-
"stringValue": "invalid json",
185+
"stringValue": "invalid json{",
157186
"dataType": "String",
158187
}
159188
},
@@ -167,8 +196,6 @@ def test_set_context_exception_handled(self):
167196
"Unable to set dsm context: JSON parsing error"
168197
)
169198

170-
self.mock_set_consume_checkpoint.assert_not_called()
171-
172199

173200
class TestGetDSMContextFromSQS(unittest.TestCase):
174201
def test_sqs_to_lambda_string_value_format(self):

0 commit comments

Comments
 (0)