MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _check

Function _check

tests/security/conftest.py:138–179  ·  view source on GitHub ↗

Try to establish a NEW connection and execute a simple command. Args: wait_time: Time to wait before checking (allows server to recover) Returns: True if server is alive and responsive False if server crashed or is unresponsive

(wait_time=1.0)

Source from the content-addressed store, hash-verified

136 """
137
138 def _check(wait_time=1.0):
139 """
140 Try to establish a NEW connection and execute a simple command.
141
142 Args:
143 wait_time: Time to wait before checking (allows server to recover)
144
145 Returns:
146 True if server is alive and responsive
147 False if server crashed or is unresponsive
148 """
149 # Wait for server to recover from rate limiting / stress
150 time.sleep(wait_time)
151
152 # Try up to 3 times with increasing delays
153 for attempt in range(3):
154 try:
155 client = SerialStudioClient(timeout=5.0)
156 client.connect()
157
158 # Execute simple command
159 result = client.command("api.getCommands")
160
161 client.disconnect()
162
163 # Verify we got a valid response
164 if isinstance(result, dict) or isinstance(result, list):
165 return True
166
167 except ConnectionRefusedError:
168 # Server not accepting connections - likely crashed
169 if attempt == 2: # Last attempt
170 return False
171 time.sleep(2.0 * (attempt + 1)) # Exponential backoff
172
173 except (ConnectionError, TimeoutError, Exception) as e:
174 # Other errors might be rate limiting or temp issues
175 if attempt == 2: # Last attempt
176 return False
177 time.sleep(2.0 * (attempt + 1)) # Exponential backoff
178
179 return False
180
181 return _check
182

Callers

nothing calls this directly

Calls 4

connectMethod · 0.95
commandMethod · 0.95
disconnectMethod · 0.95
SerialStudioClientClass · 0.90

Tested by

no test coverage detected