Documentation
¶
Overview ¶
Package mockgw 是一个可注入故障的 mock LLM/OCR 网关,只给 e2e 测试用,不属于库的公开 API。 零新依赖:只用标准库(net/http/httptest + math/rand 固定种子)。
把生产环境踩过的坑做成开关:
- Latency:每个正常请求固定延迟(模拟网关真实处理耗时,也用来撑起可观测的并发);
- BusyAfterConcurrency:并发超过 n 时返回 HTTP 200、但 body 里藏 busy 错误事件 (复刻"错误藏在 200 的 SSE 体里"的真实网关行为——HTTP 状态码骗人);
- FailRate:固定种子的随机 HTTP 500(同种子同序列,CI 可复现);
- CrashAfterConcurrency:并发超过 n 时直接掐断 TCP 连接(复刻并发打爆后断连的网关);
- BusyFirstN:前 n 个请求定向返回 busy 体,与并发无关(单独复刻"SSE 藏错误"场景)。
响应体约定(见 specs/003-m3-polish/data-model.md 第 5 节):
- 正常:HTTP 200,body `data: {"ok":true}`(请求带 body 时回显成 `data: {"ok":true,"echo":<请求体>}`,要求请求体是合法 JSON);
- busy:HTTP 200,body `data: {"error":"busy"}`;
- 随机失败:HTTP 500;
- 断连:不写任何响应,直接关连接,客户端看到 EOF/连接重置。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway 一个跑在 httptest.Server 上的 mock 网关,带原子的并发观测口。
func (*Gateway) MaxConcurrency ¶
MaxConcurrency 观测到的最大并发(原子峰值,竞态下不少算)。
type Option ¶
type Option func(*Gateway)
Option 网关的故障开关。
func BusyAfterConcurrency ¶
BusyAfterConcurrency 并发超过 n 时返回 HTTP 200 + body 里的 busy 错误事件。
func BusyFirstN ¶
BusyFirstN 前 n 个请求(按到达顺序)定向返回 busy 体,与并发无关。 专门给"SSE 藏错误 → handler 判定 ErrThrottled → 重排后成功"这条路径用。
func CrashAfterConcurrency ¶
CrashAfterConcurrency 并发超过 n 时不写任何响应、直接关掉 TCP 连接。
Click to show internal directories.
Click to hide internal directories.