-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: try to implement websocket server 409 integration test
- Loading branch information
Filip Maj
committed
Nov 22, 2024
1 parent
f2bb2d2
commit 2e7dc79
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
73 changes: 73 additions & 0 deletions
73
tests/adapter_tests/socket_mode/test_websocket_server_failures.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import logging | ||
import time | ||
|
||
from slack_sdk import WebClient | ||
|
||
from slack_bolt import App | ||
from slack_bolt.adapter.socket_mode.websocket_client import SocketModeHandler | ||
from .mock_socket_mode_server import ( | ||
start_socket_mode_server, | ||
stop_socket_mode_server, | ||
) | ||
from .mock_web_api_server import ( | ||
setup_mock_web_api_server, | ||
cleanup_mock_web_api_server, | ||
) | ||
from ...utils import remove_os_env_temporarily, restore_os_env | ||
|
||
|
||
class TestSocketModeServerFailures: | ||
logger = logging.getLogger(__name__) | ||
|
||
def setup_method(self): | ||
self.old_os_env = remove_os_env_temporarily() | ||
setup_mock_web_api_server(self) | ||
self.web_client = WebClient( | ||
token="xoxb-api_test", | ||
base_url="http://localhost:8888", | ||
) | ||
start_socket_mode_server(self, 3012) | ||
|
||
def teardown_method(self): | ||
cleanup_mock_web_api_server(self) | ||
restore_os_env(self.old_os_env) | ||
stop_socket_mode_server(self) | ||
|
||
def test_interactions(self): | ||
|
||
app = App(client=self.web_client) | ||
|
||
result = {"shortcut": False, "command": False} | ||
|
||
@app.shortcut("do-something") | ||
def shortcut_handler(ack): | ||
result["shortcut"] = True | ||
ack() | ||
|
||
@app.command("/hello-socket-mode") | ||
def command_handler(ack): | ||
result["command"] = True | ||
ack() | ||
|
||
handler = SocketModeHandler( | ||
app_token="xapp-A111-222-xyz", | ||
app=app, | ||
trace_enabled=True, | ||
) | ||
try: | ||
handler.client.wss_uri = "ws://localhost:3012/error" | ||
handler.client.default_auto_reconnect_enabled = True | ||
|
||
handler.connect() | ||
time.sleep(2) # wait for the message receiver | ||
assert handler.client.is_connected() is True | ||
logging.info("is client connected?") | ||
logging.info(handler.client.is_connected()) | ||
|
||
# handler.client.send_message("foo") | ||
|
||
# time.sleep(2) | ||
# assert result["shortcut"] is True | ||
# assert result["command"] is True | ||
finally: | ||
handler.client.close() |