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

test: try to implement websocket server 409 integration test #1205

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions tests/adapter_tests/socket_mode/mock_socket_mode_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def reset_server_state():

test.reset_server_state = reset_server_state

async def error(request: web.Request):
return web.Response(status=409, text="Unexpected server response: 409")

async def health(request: web.Request):
wr = web.Response()
await wr.prepare(request)
Expand Down Expand Up @@ -56,6 +59,7 @@ async def link(request: web.Request):
app.add_routes(
[
web.get("/link", link),
web.get("/error", error),
web.get("/health", health),
]
)
Expand Down
73 changes: 73 additions & 0 deletions tests/adapter_tests/socket_mode/test_websocket_server_failures.py
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()
Loading