Repository navigation
fix(socket_mode): seed last_ping_pong_time on first ping in builtin client #1998
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
base: main
Are you sure you want to change the base?
Changes from all commits
01cba5b
1da97d2
096c9ca
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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| import ssl | ||
| import time | ||
| import unittest | ||
| from unittest.mock import patch, sentinel | ||
| from unittest.mock import MagicMock, patch, sentinel | ||
| from threading import Thread | ||
|
|
||
| from slack_sdk import WebClient | ||
|
|
@@ -126,6 +126,23 @@ def run(): | |
|
|
||
| self.assertIsNotNone(conn) | ||
|
|
||
| def test_check_state_seeds_last_ping_pong_time_on_first_ping(self): | ||
| conn = Connection(url="wss://example.com", logger=self.logger) | ||
| conn.sock = MagicMock() | ||
| self.assertIsNone(conn.last_ping_pong_time) | ||
| with patch.object(conn, "ping"): | ||
| conn.check_state() | ||
| self.assertIsNotNone(conn.last_ping_pong_time) | ||
|
|
||
| def test_check_state_does_not_overwrite_existing_last_ping_pong_time(self): | ||
| conn = Connection(url="wss://example.com", logger=self.logger) | ||
| conn.sock = MagicMock() | ||
| existing_time = time.time() - 1 | ||
| conn.last_ping_pong_time = existing_time | ||
| with patch.object(conn, "ping"): | ||
| conn.check_state() | ||
| self.assertEqual(conn.last_ping_pong_time, existing_time) | ||
|
|
||
| # ---------------------------------- | ||
|
Contributor
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. What do you think about adding a test that covers the bug in the issue: with no pong ever arriving, the stale check disconnects? |
||
| # FrameHeader | ||
|
|
||
|
|
||
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.
last_ping_pong_timeis public, and today only a pong ever sets it, so apps use it as a liveness signal. For example, a health check likepong is not None and time.time() - pong < Nwould report a never-ponged connection as healthy for ~20s with this change. Could we leave it pong-only and give the stale check its own baseline?Setting it after
ping()means the clock only starts once a ping actually goes out, and it needs to be set once, not on every ping. Otherwise its age never exceeds one interval and the stale check never fires.