Skip to content

Commit 6a2163f

Browse files
committed
Testing for profiling_enabled.
1 parent dd40042 commit 6a2163f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_wrapper.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,34 @@ def lambda_handler(event, context):
831831
assert response == expected_response
832832
assert len(SpanExceptionHandler_enable_calls) == 1
833833
assert len(SignalUploader_periodic_calls) == 1
834+
835+
836+
@patch("datadog_lambda.config.Config.profiling_enabled", True)
837+
def test_profiling_enabled(monkeypatch):
838+
importlib.reload(wrapper)
839+
840+
original_Profiler_start = wrapper.profiler.Profiler.start
841+
Profiler_start_calls = []
842+
843+
def Profiler_start(*args, **kwargs):
844+
Profiler_start_calls.append((args, kwargs))
845+
return original_Profiler_start(*args, **kwargs)
846+
847+
monkeypatch.setattr('datadog_lambda.wrapper.is_new_sandbox', lambda: True)
848+
monkeypatch.setattr(
849+
"datadog_lambda.wrapper.profiler.Profiler.start", Profiler_start
850+
)
851+
852+
expected_response = {
853+
"statusCode": 200,
854+
"body": "This should be returned",
855+
}
856+
857+
@wrapper.datadog_lambda_wrapper
858+
def lambda_handler(event, context):
859+
return expected_response
860+
861+
response = lambda_handler({}, get_mock_context())
862+
863+
assert response == expected_response
864+
assert len(Profiler_start_calls) == 1

0 commit comments

Comments
 (0)