-
Notifications
You must be signed in to change notification settings - Fork 276
fix: make the function handler timeout 5 seconds #1348
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
Merged
WilliamBergamin
merged 6 commits into
main
from
bump-timout-for-synchronous-function-execution
Aug 13, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9752198
fix: make the function handler timeout 5 seconds
WilliamBergamin 3cd5438
Update test_function.py
WilliamBergamin 290017c
Update slack_bolt/listener/thread_runner.py
WilliamBergamin 610d52b
Update slack_bolt/app/app.py
WilliamBergamin 08db981
improve based on feedback
WilliamBergamin 21ab6c4
fix linting issues
WilliamBergamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,7 +149,7 @@ async def run_ack_function_asynchronously( | |
| self._start_lazy_function(lazy_func, request) | ||
|
|
||
| # await for the completion of ack() in the async listener execution | ||
| while ack.response is None and time.time() - starting_time <= 3: | ||
| while ack.response is None and time.time() - starting_time <= listener.acknowledgement_timeout: | ||
|
Member
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. 👾 praise: Love to see this! |
||
| await asyncio.sleep(0.01) | ||
|
|
||
| if response is None and ack.response is None: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import time | ||
|
|
||
| import pytest | ||
| from unittest.mock import AsyncMock, Mock | ||
| from slack_sdk.signature import SignatureVerifier | ||
| from slack_sdk.web.async_client import AsyncWebClient | ||
|
|
||
|
|
@@ -56,6 +57,10 @@ def build_request_from_body(self, message_body: dict) -> AsyncBoltRequest: | |
| timestamp, body = str(int(time.time())), json.dumps(message_body) | ||
| return AsyncBoltRequest(body=body, headers=self.build_headers(timestamp, body)) | ||
|
|
||
| def setup_time_mocks(self, *, monkeypatch: pytest.MonkeyPatch, time_mock: Mock, sleep_mock: AsyncMock): | ||
| monkeypatch.setattr(time, "time", time_mock) | ||
| monkeypatch.setattr(asyncio, "sleep", sleep_mock) | ||
|
|
||
|
||
| @pytest.mark.asyncio | ||
| async def test_mock_server_is_running(self): | ||
| resp = await self.web_client.api_test() | ||
|
|
@@ -130,19 +135,47 @@ async def test_auto_acknowledge_false_with_acknowledging(self): | |
| await assert_auth_test_count_async(self, 1) | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_auto_acknowledge_false_without_acknowledging(self, caplog): | ||
| async def test_auto_acknowledge_false_without_acknowledging(self, caplog, monkeypatch): | ||
| app = AsyncApp( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
| app.function("reverse", auto_acknowledge=False)(just_no_ack) | ||
|
|
||
| request = self.build_request_from_body(function_body) | ||
| self.setup_time_mocks( | ||
| monkeypatch=monkeypatch, | ||
| time_mock=Mock(side_effect=[current_time for current_time in range(100)]), | ||
| sleep_mock=AsyncMock(), | ||
| ) | ||
| response = await app.async_dispatch(request) | ||
| assert response.status == 404 | ||
| await assert_auth_test_count_async(self, 1) | ||
| assert f"WARNING {just_no_ack.__name__} didn't call ack()" in caplog.text | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_function_handler_timeout(self, monkeypatch): | ||
| app = AsyncApp( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
| app.function("reverse", auto_acknowledge=False)(just_no_ack) | ||
| request = self.build_request_from_body(function_body) | ||
|
|
||
| sleep_mock = AsyncMock() | ||
| self.setup_time_mocks( | ||
| monkeypatch=monkeypatch, | ||
| time_mock=Mock(side_effect=[current_time for current_time in range(100)]), | ||
| sleep_mock=sleep_mock, | ||
| ) | ||
|
|
||
| response = await app.async_dispatch(request) | ||
|
|
||
| assert response.status == 404 | ||
| await assert_auth_test_count_async(self, 1) | ||
| assert ( | ||
| sleep_mock.call_count == 5 | ||
| ), f"Expected handler to time out after calling time.sleep 5 times, but it was called {sleep_mock.call_count} times" | ||
|
|
||
|
|
||
| function_body = { | ||
| "token": "verification_token", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.