知识卡片

结构图卡 · 4545.g.8.s.8 · 生成模型:GPT-6

超时返回不会自动取消请求

理解等级:高级

select添加计时分支可限制Racer等待,但退出后两个http.Get仍可能继续,败者也不会因胜者已返回自动停止。资源和取消需另行传递到请求;测试结束调用Server.Close还可能等在途处理器,因此函数快速超时不等于整个测试立刻结束。

结构图:

sequenceDiagram
participant R as Racer
participant A as 请求A
participant B as 请求B
participant T as 计时信号
R->>A: 启动http.Get
R->>B: 启动http.Get
T-->>R: 等待期到
R-->>R: 返回超时错误
Note over A,B: 原例无取消,仍可能继续

图表达原例数据或生命周期边界,不表示已运行验证。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Select · 查看原书依据

      se <-ping(b): return b, nil case <-time.After(timeout): return "", fmt.Errorf("timed out waiting for %s and %s", a, b) } }

    参考来源

    - 位置:《通过测试学习 Go 编程》Select,spine015(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/14.html)。 - 结论依据:原例time.After只改变返回分支,ping没有取消或清理。 - 原始内容:se <-ping(b): return b, nil case <-time.After(timeout): return "", fmt.Errorf("timed out waiting for %s and %s", a, b) } }