Commit 2c87a38
huangqing.zhu
test(lru): TestWorkerComparison hashPool 阈值放宽 + 等 callback 回收
CI Linux 报:
workerHashPool fail at line 254:
Expected '47' to be less than '29' (but it wasn't)
根因:stdlib time.AfterFunc callback 是在独立 goroutine 跑(runtime/
time.go: 'go arg.(func())()')。50 engine × AfterFunc(interval=100ms,
PushJob) 在 timer 触发瞬间有 50 个 callback goroutine 共存(每个跑
PushJob 完才退)。CI Linux 调度慢于 macOS,callback 回收延迟,导致
increased 远超 numWorkers。
修:
1. 等够 3*interval=300ms 让 callback 都跑完退出(原 50ms 不足以让
100ms timer 都触发)
2. 阈值从 engineCount/2+numWorkers=29 → engineCount+numWorkers=54。
54 容纳'瞬时所有 timer callback 共存 + worker'上限。仍能在'真
的退化为 per-engine 常驻'(每 engine 多个常驻 goroutine 累积)
时报警。
测试核心契约不变:'workerHashPool 内 worker 数 = numWorkers,不随
engineCount 线性增长'。本地 5/5 跑稳定 + -race 通过。
注:本批 commit cbe1997 修了 worker.Start defer close(closedChan)
时机让 GoroutinePool.Close 真等 worker 退;这增强了 join 语义的正
确性,但与本测试 timer callback goroutine 共存量无关——本测试在
hashPool Close 之前就采样 NumGoroutine。1 parent 80c3df9 commit 2c87a38
1 file changed
Lines changed: 20 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
226 | | - | |
| 225 | + | |
227 | 226 | | |
228 | 227 | | |
229 | 228 | | |
| |||
237 | 236 | | |
238 | 237 | | |
239 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
240 | 246 | | |
241 | 247 | | |
242 | 248 | | |
243 | 249 | | |
244 | 250 | | |
245 | 251 | | |
246 | 252 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
254 | 265 | | |
255 | 266 | | |
256 | 267 | | |
| |||
0 commit comments