| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- """Verify ResolveTimeout logic: ini waitTime(seconds) -> payTimeout(ms)."""
- import re
- # 抽取 HttpServices.cs 里的 ResolveTimeout 逻辑,用 Python 等价实现验证换算
- src = open(r"E:\普瑞工作文件夹\源码\Project\win-service-machine-dll\UppPay\HttpServices.cs",
- encoding="utf-8-sig").read()
- m = re.search(r"private int ResolveTimeout.*?\n \}", src, re.S)
- print("=== ResolveTimeout 源码 ===")
- print(m.group(0) if m else "NOT FOUND")
- print()
- def resolve_timeout(ini, timeout_type):
- """模拟 C# 实现"""
- try:
- if timeout_type == "PAY":
- s = ini.get("Config", {}).get("waitTime", "")
- if s.strip() and int(s.strip()) > 0:
- return int(s.strip()) * 1000
- return 90000
- else:
- s = ini.get("Config", {}).get("queryTimeout", "")
- if s.strip() and int(s.strip()) > 0:
- return int(s.strip())
- return 10000
- except Exception:
- return 90000 if timeout_type == "PAY" else 10000
- cases = [
- ("现场 ini 原样 waitTime=60", {"Config": {"waitTime": "60", "warningTime": "5"}}, 60000, 10000),
- ("改后 waitTime=90", {"Config": {"waitTime": "90"}}, 90000, 10000),
- ("ini 完全没有 Config 段", {}, 90000, 10000),
- ("waitTime 空值", {"Config": {"waitTime": ""}}, 90000, 10000),
- ("waitTime 非法值", {"Config": {"waitTime": "abc"}}, 90000, 10000),
- ("waitTime=0", {"Config": {"waitTime": "0"}}, 90000, 10000),
- ("配了 queryTimeout=15000", {"Config": {"waitTime": "90", "queryTimeout": "15000"}}, 90000, 15000),
- ]
- print("%-26s %-12s %-12s %s" % ("场景", "PAY(ms)", "QUERY(ms)", "结论"))
- print("-" * 70)
- ok = True
- for name, ini, exp_pay, exp_q in cases:
- got_pay = resolve_timeout(ini, "PAY")
- got_q = resolve_timeout(ini, "QUERY")
- good = (got_pay == exp_pay and got_q == exp_q)
- ok = ok and good
- print("%-26s %-12d %-12d %s" % (name, got_pay, got_q, "PASS" if good else "FAIL(exp %d/%d)" % (exp_pay, exp_q)))
- print("-" * 70)
- print("ALL PASS" if ok else "HAS FAILURE")
|