MCPcopy Create free account
hub / github.com/Tong89/smartNode / TestConcurrentErrorPaths

Class TestConcurrentErrorPaths

tests/test_concurrency.py:261–344  ·  view source on GitHub ↗

并发触发错误路径 —— 确保 RLock 覆盖错误流。

Source from the content-addressed store, hash-verified

259# ---------------------------------------------------------------------------
260
261class TestConcurrentErrorPaths:
262 """并发触发错误路径 —— 确保 RLock 覆盖错误流。"""
263
264 def test_concurrent_nonexistent_satellite_no_exception(self, isolated_engine):
265 """并发指定不存在的卫星,每次都应以 status='error' 结果返回,不抛异常。"""
266 bad_payload = {
267 "data_type": "TASK_CMD",
268 "data_size": 50,
269 "priority": 5,
270 "max_delay": 600,
271 "satellite_id": "NONEXISTENT_SAT_CONCURRENT_TEST",
272 }
273 results = []
274 errors = []
275 barrier = threading.Barrier(6)
276
277 def worker():
278 barrier.wait()
279 for _ in range(5):
280 try:
281 r = isolated_engine.submit_request(dict(bad_payload))
282 results.append(r)
283 except Exception as exc:
284 errors.append(exc)
285
286 threads = [threading.Thread(target=worker) for _ in range(6)]
287 for t in threads:
288 t.start()
289 for t in threads:
290 t.join(timeout=30)
291
292 assert errors == [], f"不存在卫星的并发调用出现异常: {errors}"
293 for r in results:
294 assert r.get("status") == "error"
295
296 def test_rejected_count_incremented_for_missing_satellite(self, isolated_engine):
297 """不存在卫星请求应计入 rejected_requests。"""
298 bad_payload = dict(_VALID_PAYLOAD)
299 bad_payload["satellite_id"] = "NO_SUCH_SAT_XYZ"
300 n = 5
301 before = isolated_engine.stats["rejected_requests"]
302 for _ in range(n):
303 isolated_engine.submit_request(dict(bad_payload))
304 assert isolated_engine.stats["rejected_requests"] == before + n
305
306 def test_mixed_valid_and_invalid_concurrent(self, isolated_engine):
307 """合法请求与非法卫星请求混合并发,计数器仍自洽。"""
308 good = dict(_VALID_PAYLOAD)
309 bad = dict(_VALID_PAYLOAD)
310 bad["satellite_id"] = "MIXED_BAD_SAT_99"
311
312 results = []
313 errors = []
314 barrier = threading.Barrier(4)
315
316 def good_worker():
317 barrier.wait()
318 for _ in range(5):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected