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>
This commit is contained in:
RazCrimson 2023-05-08 05:21:24 +05:30 committed by GitHub
parent 576e47aaac
commit 443a35360f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -1164,8 +1164,9 @@ class ContainerApiMixin:
'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(

View File

@ -1528,10 +1528,21 @@ class ContainerTest(BaseAPIClientTest):
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)