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

Function TestPool_ConcurrentAccess

pkg/core/pool_test.go:298–351  ·  view source on GitHub ↗

TestPool_ConcurrentAccess 测试并发访问

(t *testing.T)

Source from the content-addressed store, hash-verified

296
297// TestPool_ConcurrentAccess 测试并发访问
298func TestPool_ConcurrentAccess(t *testing.T) {
299 deps := createTestDeps(t)
300 pool := NewPool(&PoolOptions{
301 Dependencies: deps,
302 MaxAgents: 100,
303 })
304 defer func() {
305 if err := pool.Shutdown(); err != nil {
306 t.Errorf("Shutdown failed: %v", err)
307 }
308 }()
309
310 ctx := context.Background()
311 concurrency := 50
312 var wg sync.WaitGroup
313
314 // 并发创建 Agent
315 for i := range concurrency {
316 wg.Add(1)
317 go func(idx int) {
318 defer wg.Done()
319
320 config := createTestConfig("concurrent-agent-" + string(rune('0'+idx)))
321 _, err := pool.Create(ctx, config)
322 if err != nil {
323 t.Logf("Failed to create agent %d: %v", idx, err)
324 }
325 }(i)
326 }
327
328 wg.Wait()
329
330 // 验证池大小
331 size := pool.Size()
332 if size != concurrency {
333 t.Logf("Expected %d agents, got %d (some creates may have failed)", concurrency, size)
334 }
335
336 // 并发读取 Agent
337 for i := range concurrency {
338 wg.Add(1)
339 go func(idx int) {
340 defer wg.Done()
341
342 agentID := "concurrent-agent-" + string(rune('0'+idx))
343 _, exists := pool.Get(agentID)
344 if !exists {
345 t.Logf("Agent %s not found", agentID)
346 }
347 }(i)
348 }
349
350 wg.Wait()
351}
352
353// TestPool_Shutdown 测试关闭池
354func TestPool_Shutdown(t *testing.T) {

Callers

nothing calls this directly

Calls 9

ShutdownMethod · 0.95
CreateMethod · 0.95
SizeMethod · 0.95
GetMethod · 0.95
createTestDepsFunction · 0.85
NewPoolFunction · 0.85
createTestConfigFunction · 0.85
WaitMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected