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

Class TestHighUtilizationBehavior

tests/load/test_stress_engine.py:415–458  ·  view source on GitHub ↗

验证资源紧张(高占用)下引擎行为符合预期。

Source from the content-addressed store, hash-verified

413
414
415class TestHighUtilizationBehavior:
416 """验证资源紧张(高占用)下引擎行为符合预期。"""
417
418 def test_no_exception_under_simulated_load(self, stepped_engine):
419 """步进推进 + 批量提交,引擎在资源紧张前后均不抛出异常。"""
420 # 提交大量低优先级请求
421 errors = []
422 for i in range(100):
423 try:
424 payload = {
425 "data_type": "DATA_SLICE",
426 "data_size": 500,
427 "priority": 1 + (i % 3),
428 "max_delay": 300,
429 }
430 stepped_engine.submit_request(payload)
431 except Exception as exc:
432 errors.append(exc)
433
434 assert len(errors) == 0, f"步进负载下出现异常: {errors[:3]}"
435
436 def test_high_priority_vs_low_priority_under_load(self, stepped_engine):
437 """在连续提交后,高/低优先级请求均能正常返回结果字典(不崩溃)。"""
438 hi_results = [stepped_engine.submit_request(dict(_HIGH_PRI_PAYLOAD)) for _ in range(40)]
439 lo_results = [stepped_engine.submit_request(dict(_LOW_PRI_PAYLOAD)) for _ in range(40)]
440
441 for r in hi_results + lo_results:
442 assert isinstance(r, dict), "submit_request 必须始终返回字典"
443
444 def test_stats_remain_consistent_under_stepped_load(self, stepped_engine):
445 """步进 + 批量提交后,统计计数守恒。"""
446 # 额外步进 30 秒
447 advance_engine(stepped_engine, total_seconds=30.0, step=10.0)
448
449 for _ in range(80):
450 stepped_engine.submit_request(dict(_HIGH_PRI_PAYLOAD))
451
452 stats = stepped_engine.stats
453 total = stats["total_requests"]
454 accepted = stats["accepted_requests"]
455 rejected = stats["rejected_requests"]
456 assert total == accepted + rejected, (
457 f"步进后计数不守恒: total={total}, accepted={accepted}, rejected={rejected}"
458 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected