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

Function TestMemoryStability

pkg/events/bus_test.go:283–324  ·  view source on GitHub ↗

TestMemoryStability 测试内存稳定性(防止泄漏)

(t *testing.T)

Source from the content-addressed store, hash-verified

281
282// TestMemoryStability 测试内存稳定性(防止泄漏)
283func TestMemoryStability(t *testing.T) {
284 config := &EventBusConfig{
285 MaxTimelineSize: 1000,
286 MaxTimelineAge: 0,
287 CleanupInterval: 50 * time.Millisecond,
288 }
289 eb := NewEventBusWithConfig(config)
290 defer eb.Close()
291
292 // 分批发送事件,给清理 worker 时间工作
293 batches := 100
294 eventsPerBatch := 100
295
296 for batch := range batches {
297 // 快速发送一批事件
298 for i := range eventsPerBatch {
299 eb.EmitProgress(&types.ProgressTextChunkEvent{
300 Step: batch*eventsPerBatch + i,
301 Delta: "test data",
302 })
303 }
304
305 // 每批之后给清理 worker 一些时间
306 if batch%10 == 0 {
307 time.Sleep(100 * time.Millisecond)
308 count := eb.GetTimelineCount()
309 // 应该在合理范围内
310 if count > 1500 {
311 t.Errorf("timeline growing too large: %d at batch %d", count, batch)
312 }
313 }
314 }
315
316 // 等待最后一次清理
317 time.Sleep(200 * time.Millisecond)
318
319 // 最终检查
320 finalCount := eb.GetTimelineCount()
321 if finalCount > 1100 {
322 t.Errorf("final timeline count too large: %d (expected <= 1100)", finalCount)
323 }
324}
325
326// TestUnsubscribeMultipleChannels 测试多通道取消订阅
327func TestUnsubscribeMultipleChannels(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