Reconnect after transient socket disconnects

This commit is contained in:
Tanner committed 2026-11-14 00:21:19 +00:00
1 parent 62ed14e334
commit 7d6fc8aa81
2 files changed
+65 -1

No files matched your search

+22
View File
@@ -30,6 +30,28 @@ class FakeGame:
class TestWebInventoryAPI(unittest.TestCase):
def test_connection_loop_retries_socket_disconnects_without_crashing(self):
state = Munch(running=True)
attempts = []
delays = []
def connector(global_state):
attempts.append(True)
if len(attempts) == 1:
raise BrokenPipeError(32, 'Broken pipe')
if len(attempts) == 2:
raise ValueError('I/O operation on closed file')
global_state.running = False
mosfet_web._run_connection_loop(
state, connector, sleep=lambda delay: delays.append(delay))
self.assertEqual(len(attempts), 3)
self.assertEqual(delays, [1.0, 2.0])
self.assertFalse(state.connected)
self.assertIs(state.connection, False)
self.assertEqual(state.connection_status, 'reconnecting')
def test_web_port_uses_bot_name_suffix(self):
for suffix in range(1, 10):
with self.subTest(suffix=suffix):