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

Function TestPool_Create

pkg/core/pool_test.go:63–103  ·  view source on GitHub ↗

TestPool_Create 测试创建 Agent

(t *testing.T)

Source from the content-addressed store, hash-verified

61
62// TestPool_Create 测试创建 Agent
63func TestPool_Create(t *testing.T) {
64 deps := createTestDeps(t)
65 pool := NewPool(&PoolOptions{
66 Dependencies: deps,
67 MaxAgents: 5,
68 })
69 defer func() {
70 if err := pool.Shutdown(); err != nil {
71 t.Errorf("Shutdown failed: %v", err)
72 }
73 }()
74
75 ctx := context.Background()
76
77 // 创建 Agent
78 config := createTestConfig("test-agent-1")
79
80 ag, err := pool.Create(ctx, config)
81 if err != nil {
82 t.Fatalf("Failed to create agent: %v", err)
83 }
84
85 if ag == nil {
86 t.Fatal("Agent is nil")
87 }
88
89 // 验证 Agent 在池中
90 retrievedAg, exists := pool.Get("test-agent-1")
91 if !exists {
92 t.Fatal("Agent not found in pool")
93 }
94
95 if retrievedAg != ag {
96 t.Error("Retrieved agent is different from created agent")
97 }
98
99 // 验证池大小
100 if pool.Size() != 1 {
101 t.Errorf("Expected pool size 1, got %d", pool.Size())
102 }
103}
104
105// TestPool_CreateDuplicate 测试重复创建相同 ID 的 Agent
106func TestPool_CreateDuplicate(t *testing.T) {

Callers

nothing calls this directly

Calls 8

ShutdownMethod · 0.95
CreateMethod · 0.95
GetMethod · 0.95
SizeMethod · 0.95
createTestDepsFunction · 0.85
NewPoolFunction · 0.85
createTestConfigFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected