TestAutoCleanupWorker 测试自动清理 worker
(t *testing.T)
| 257 | |
| 258 | // TestAutoCleanupWorker 测试自动清理 worker |
| 259 | func TestAutoCleanupWorker(t *testing.T) { |
| 260 | config := &EventBusConfig{ |
| 261 | MaxTimelineSize: 5, |
| 262 | MaxTimelineAge: 0, |
| 263 | CleanupInterval: 200 * time.Millisecond, // 200ms 清理一次 |
| 264 | } |
| 265 | eb := NewEventBusWithConfig(config) |
| 266 | defer eb.Close() |
| 267 | |
| 268 | // 添加 10 个事件 |
| 269 | for i := range 10 { |
| 270 | eb.EmitProgress(&types.ProgressTextChunkEvent{Step: i, Delta: "test"}) |
| 271 | } |
| 272 | |
| 273 | // 等待自动清理 |
| 274 | time.Sleep(500 * time.Millisecond) |
| 275 | |
| 276 | count := eb.GetTimelineCount() |
| 277 | if count > 5 { |
| 278 | t.Errorf("expected timeline count <= 5 after auto cleanup, got %d", count) |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // TestMemoryStability 测试内存稳定性(防止泄漏) |
| 283 | func TestMemoryStability(t *testing.T) { |
nothing calls this directly
no test coverage detected