Skip to content

Commit

Permalink
Fix container.stats infinite blocking on stream mode (#3120)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
RazCrimson authored May 7, 2023
1 parent 576e47a commit 443a353
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 443a353

Please sign in to comment.