@@ -40,6 +40,7 @@ def _listener(collector, *, check=None) -> ArgocdApplicationStreamListener:
4040 endpoint = GENRESOURCES_ENDPOINT ,
4141 auth_token = None ,
4242 backoff_max_seconds = 10 ,
43+ read_timeout_seconds = 60 ,
4344 http = Mock (),
4445 )
4546
@@ -174,6 +175,17 @@ def test_ensure_listener_gives_the_listener_its_own_http_session():
174175 assert http is not check .http # a dedicated RequestsWrapper, not the check's shared session
175176
176177
178+ def test_ensure_listener_passes_the_configured_read_timeout ():
179+ check = _check (genresources_stream_applications_enabled = True , genresources_stream_read_timeout_seconds = 123 )
180+ collector = check ._resource_collector
181+
182+ with patch ("datadog_checks.argocd.resources.ArgocdApplicationStreamListener" ) as listener_cls :
183+ listener_cls .return_value .is_alive .return_value = False
184+ collector ._ensure_listener ()
185+
186+ assert listener_cls .call_args .kwargs ["read_timeout_seconds" ] == 123
187+
188+
177189def test_collect_with_stream_emits_stream_up_one_when_the_listener_is_connected (aggregator ):
178190 check = _check (genresources_stream_applications_enabled = True )
179191 collector = check ._resource_collector
@@ -263,7 +275,13 @@ def close(self):
263275 http = Mock ()
264276 http .get .return_value = _Resp ()
265277 listener = ArgocdApplicationStreamListener (
266- check , collector , endpoint = GENRESOURCES_ENDPOINT , auth_token = None , backoff_max_seconds = 10 , http = http
278+ check ,
279+ collector ,
280+ endpoint = GENRESOURCES_ENDPOINT ,
281+ auth_token = None ,
282+ backoff_max_seconds = 10 ,
283+ read_timeout_seconds = 60 ,
284+ http = http ,
267285 )
268286
269287 with patch .object (check , "submit_generic_resource" ) as submit :
@@ -293,7 +311,13 @@ def close(self):
293311 http = Mock ()
294312 http .get .return_value = _Resp ()
295313 listener = ArgocdApplicationStreamListener (
296- check , collector , endpoint = GENRESOURCES_ENDPOINT , auth_token = None , backoff_max_seconds = 10 , http = http
314+ check ,
315+ collector ,
316+ endpoint = GENRESOURCES_ENDPOINT ,
317+ auth_token = None ,
318+ backoff_max_seconds = 10 ,
319+ read_timeout_seconds = 60 ,
320+ http = http ,
297321 )
298322
299323 with patch .object (check , "submit_generic_resource" ):
@@ -302,6 +326,39 @@ def close(self):
302326 assert got_data is True # data arrived before the drop; _stream_once caught the error and reported it
303327
304328
329+ def test_stream_once_inherits_wrapper_auth_when_no_token ():
330+ check = _check (genresources_stream_applications_enabled = True , genresources_auth_token = None )
331+ collector = check ._resource_collector
332+
333+ class _Resp :
334+ def raise_for_status (self ):
335+ pass
336+
337+ def iter_lines (self ):
338+ return iter (())
339+
340+ def close (self ):
341+ pass
342+
343+ http = Mock ()
344+ http .get .return_value = _Resp ()
345+ listener = ArgocdApplicationStreamListener (
346+ check ,
347+ collector ,
348+ endpoint = GENRESOURCES_ENDPOINT ,
349+ auth_token = None ,
350+ backoff_max_seconds = 10 ,
351+ read_timeout_seconds = 60 ,
352+ http = http ,
353+ )
354+
355+ listener ._stream_once ()
356+
357+ kwargs = http .get .call_args .kwargs
358+ assert "headers" not in kwargs # must not clobber the wrapper's configured auth
359+ assert not kwargs .get ("extra_headers" ) # no token -> nothing added, inherited auth survives
360+
361+
305362def test_handle_line_emits_events_received_metric_matching_metadata (aggregator ):
306363 check = _check (genresources_stream_applications_enabled = True )
307364 collector = check ._resource_collector
@@ -357,7 +414,13 @@ def close(self):
357414 http = Mock ()
358415 http .get .return_value = _Resp ()
359416 listener = ArgocdApplicationStreamListener (
360- check , collector , endpoint = GENRESOURCES_ENDPOINT , auth_token = None , backoff_max_seconds = 1 , http = http
417+ check ,
418+ collector ,
419+ endpoint = GENRESOURCES_ENDPOINT ,
420+ auth_token = None ,
421+ backoff_max_seconds = 1 ,
422+ read_timeout_seconds = 60 ,
423+ http = http ,
361424 )
362425
363426 listener .start ()
0 commit comments