Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container.stats infinite blocking on stream mode #3120

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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