-
Notifications
You must be signed in to change notification settings - Fork 847
Fix #1377 Add unit tests for #1367 changes #1378
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,10 @@ def convert_params(values: dict) -> dict: | |
| ) | ||
| except aiohttp.ContentTypeError: | ||
| logger.debug(f"No response data returned from the following API call: {api_url}.") | ||
| retry_response = RetryHttpResponse( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a potential bug |
||
| status_code=res.status, | ||
| headers=res.headers, | ||
| ) | ||
| except json.decoder.JSONDecodeError: | ||
| try: | ||
| body: str = await res.text() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,5 +199,5 @@ def validate(self): | |
| """ | ||
| if self.status_code == 200 and self.data and (isinstance(self.data, bytes) or self.data.get("ok", False)): | ||
| return self | ||
| msg = f"The request to the Slack API failed. (url: {self.api_url})" | ||
| msg = f"The request to the Slack API failed. (url: {self.api_url}, status: {self.status_code})" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for better debuggability |
||
| raise e.SlackApiError(message=msg, response=self) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import unittest | ||
|
|
||
| import slack_sdk.errors as err | ||
| from slack_sdk.http_retry.builtin_async_handlers import AsyncRateLimitErrorRetryHandler | ||
| from slack_sdk.http_retry.builtin_async_handlers import AsyncRateLimitErrorRetryHandler, AsyncServerErrorRetryHandler | ||
| from slack_sdk.web.async_client import AsyncWebClient | ||
| from tests.slack_sdk_async.helpers import async_test | ||
| from tests.slack_sdk.web.mock_web_api_server import ( | ||
|
|
@@ -19,10 +19,6 @@ def setUp(self): | |
| def tearDown(self): | ||
| cleanup_mock_web_api_server(self) | ||
|
|
||
| @async_test | ||
| async def test_api_calls_return_a_future(self): | ||
| pass | ||
|
|
||
| @async_test | ||
| async def test_remote_disconnected(self): | ||
| retry_handler = MyRetryHandler(max_retry_count=2) | ||
|
|
@@ -88,3 +84,30 @@ async def test_fatal_error(self): | |
| client.retry_handlers.append(FatalErrorRetryHandler()) | ||
| # The auto-retry should work here | ||
| await client.auth_test() | ||
|
|
||
| @async_test | ||
| async def test_retries(self): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from tests/slack_sdk_async/web/test_web_client_http_retry.py to reduce confusion for future maintainers |
||
| retry_handler = MyRetryHandler(max_retry_count=2) | ||
| client = AsyncWebClient( | ||
| token="xoxp-remote_disconnected", | ||
| base_url="http://localhost:8888", | ||
| retry_handlers=[retry_handler], | ||
| ) | ||
| try: | ||
| await client.auth_test() | ||
| self.fail("An exception is expected") | ||
| except Exception as _: | ||
| pass | ||
|
|
||
| self.assertEqual(2, retry_handler.call_count) | ||
|
|
||
| @async_test | ||
| async def test_server_error(self): | ||
| client = AsyncWebClient( | ||
| base_url="http://localhost:8888", | ||
| token="xoxb-server_error_only_once", | ||
| team_id="T111", | ||
| ) | ||
| client.retry_handlers.append(AsyncServerErrorRetryHandler()) | ||
| # The auto-retry should work here | ||
| await client.chat_postMessage(channel="C123", text="Hi there!") | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency