@@ -38,14 +38,6 @@ def setUp(self):
3838 self .mock_threadstats_flush_distributions = patcher .start ()
3939 self .addCleanup (patcher .stop )
4040
41- self .metric_lambda_stats_patcher = patch ("datadog_lambda.metric.lambda_stats" )
42- self .mock_metric_lambda_stats = self .metric_lambda_stats_patcher .start ()
43- self .addCleanup (self .metric_lambda_stats_patcher .stop )
44-
45- self .wrapper_lambda_stats_patcher = patch ("datadog_lambda.wrapper.lambda_stats" )
46- self .mock_wrapper_lambda_stats = self .wrapper_lambda_stats_patcher .start ()
47- self .addCleanup (self .wrapper_lambda_stats_patcher .stop )
48-
4941 patcher = patch ("datadog_lambda.wrapper.extract_dd_trace_context" )
5042 self .mock_extract_dd_trace_context = patcher .start ()
5143 self .mock_extract_dd_trace_context .return_value = ({}, None )
@@ -101,10 +93,16 @@ def lambda_handler(event, context):
10193
10294 lambda_handler (lambda_event , lambda_context )
10395
104- self .mock_metric_lambda_stats .distribution .assert_has_calls (
105- [call ("test.metric" , 100 , timestamp = None , tags = ANY )]
96+ self .mock_threadstats_flush_distributions .assert_has_calls (
97+ [call ([{
98+ 'metric' : 'test.metric' , 'points' : [[ANY , [100 ]]],
99+ 'type' : 'distribution' ,
100+ 'host' : None ,
101+ 'device' : None ,
102+ 'tags' : ANY ,
103+ 'interval' : 10
104+ }])]
106105 )
107- self .mock_wrapper_lambda_stats .flush .assert_called ()
108106 self .mock_extract_dd_trace_context .assert_called_with (
109107 lambda_event , lambda_context , extractor = None
110108 )
@@ -122,16 +120,11 @@ def lambda_handler(event, context):
122120 lambda_event = {}
123121 lambda_handler (lambda_event , get_mock_context ())
124122
125- self .mock_metric_lambda_stats .distribution .assert_not_called ()
126- self .mock_wrapper_lambda_stats .flush .assert_not_called ()
123+ self .mock_threadstats_flush_distributions .assert_not_called ()
127124
128125 del os .environ ["DD_FLUSH_TO_LOG" ]
129126
130127 def test_datadog_lambda_wrapper_flush_in_thread (self ):
131- # stop patchers so mock_threadstats_flush_distributions gets called
132- self .metric_lambda_stats_patcher .stop ()
133- self .wrapper_lambda_stats_patcher .stop ()
134-
135128 # force ThreadStats to flush in thread
136129 import datadog_lambda .metric as metric_module
137130
@@ -158,15 +151,7 @@ def lambda_handler(event, context):
158151 metric_module .lambda_stats .stop ()
159152 metric_module .lambda_stats .start (flush_in_thread = False )
160153
161- # resume patchers
162- self .metric_lambda_stats_patcher .start ()
163- self .wrapper_lambda_stats_patcher .start ()
164-
165154 def test_datadog_lambda_wrapper_not_flush_in_thread (self ):
166- # stop patchers so mock_threadstats_flush_distributions gets called
167- self .metric_lambda_stats_patcher .stop ()
168- self .wrapper_lambda_stats_patcher .stop ()
169-
170155 # force ThreadStats to not flush in thread
171156 import datadog_lambda .metric as metric_module
172157
@@ -193,10 +178,6 @@ def lambda_handler(event, context):
193178 metric_module .lambda_stats .stop ()
194179 metric_module .lambda_stats .start (flush_in_thread = False )
195180
196- # resume patchers
197- self .metric_lambda_stats_patcher .start ()
198- self .wrapper_lambda_stats_patcher .start ()
199-
200181 def test_datadog_lambda_wrapper_inject_correlation_ids (self ):
201182 os .environ ["DD_LOGS_INJECTION" ] = "True"
202183
@@ -445,5 +426,4 @@ def lambda_handler(event, context):
445426 lambda_handler_double_wrapped (lambda_event , get_mock_context ())
446427
447428 self .mock_patch_all .assert_called_once ()
448- self .mock_wrapper_lambda_stats .flush .assert_called_once ()
449429 self .mock_submit_invocations_metric .assert_called_once ()
0 commit comments