From 443a35360fc426479d87c810ffca8e5a253408a1 Mon Sep 17 00:00:00 2001 From: RazCrimson <52282402+RazCrimson@users.noreply.github.com> Date: Mon, 8 May 2023 05:21:24 +0530 Subject: [PATCH] Fix container.stats infinite blocking on stream mode (#3120) fix: api - container.stats infinite blocking on stream mode Includes additional test for no streaming Signed-off-by: Bharath Vignesh J K <52282402+RazCrimson@users.noreply.github.com> --- docker/api/container.py | 5 +++-- tests/unit/api_container_test.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docker/api/container.py b/docker/api/container.py index fef760300..40607e79a 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -1164,8 +1164,9 @@ def stats(self, container, decode=None, stream=True, one_shot=None): 'one_shot is only available in conjunction with ' 'stream=False' ) - return self._stream_helper(self._get(url, params=params), - decode=decode) + return self._stream_helper( + self._get(url, stream=True, params=params), decode=decode + ) else: if decode: raise errors.InvalidArgument( diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py index c605da371..c4e2250be 100644 --- a/tests/unit/api_container_test.py +++ b/tests/unit/api_container_test.py @@ -1528,10 +1528,21 @@ def test_container_stats(self): fake_request.assert_called_with( 'GET', url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stats', + stream=True, timeout=60, params={'stream': True} ) + def test_container_stats_without_streaming(self): + self.client.stats(fake_api.FAKE_CONTAINER_ID, stream=False) + + fake_request.assert_called_with( + 'GET', + url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stats', + timeout=60, + params={'stream': False} + ) + def test_container_stats_with_one_shot(self): self.client.stats( fake_api.FAKE_CONTAINER_ID, stream=False, one_shot=True)