MCPcopy Create free account
hub / github.com/astercloud/aster / TestAutoCleanupWorker

Function TestAutoCleanupWorker

pkg/events/bus_test.go:259–280  ·  view source on GitHub ↗

TestAutoCleanupWorker 测试自动清理 worker

(t *testing.T)

Source from the content-addressed store, hash-verified

257
258// TestAutoCleanupWorker 测试自动清理 worker
259func 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 测试内存稳定性(防止泄漏)
283func TestMemoryStability(t *testing.T) {

Callers

nothing calls this directly

Calls 4

NewEventBusWithConfigFunction · 0.85
EmitProgressMethod · 0.80
GetTimelineCountMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected