TestPool_MaxCapacity 测试池容量限制
(t *testing.T)
| 133 | |
| 134 | // TestPool_MaxCapacity 测试池容量限制 |
| 135 | func TestPool_MaxCapacity(t *testing.T) { |
| 136 | deps := createTestDeps(t) |
| 137 | maxAgents := 3 |
| 138 | pool := NewPool(&PoolOptions{ |
| 139 | Dependencies: deps, |
| 140 | MaxAgents: maxAgents, |
| 141 | }) |
| 142 | defer func() { |
| 143 | if err := pool.Shutdown(); err != nil { |
| 144 | t.Errorf("Shutdown failed: %v", err) |
| 145 | } |
| 146 | }() |
| 147 | |
| 148 | ctx := context.Background() |
| 149 | |
| 150 | // 创建 maxAgents 个 Agent |
| 151 | for i := range maxAgents { |
| 152 | config := createTestConfig("test-agent-" + string(rune('1'+i))) |
| 153 | _, err := pool.Create(ctx, config) |
| 154 | if err != nil { |
| 155 | t.Fatalf("Failed to create agent %d: %v", i, err) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // 尝试创建超过容量的 Agent |
| 160 | config := createTestConfig("overflow-agent") |
| 161 | |
| 162 | _, err := pool.Create(ctx, config) |
| 163 | if err == nil { |
| 164 | t.Error("Expected error when pool is full") |
| 165 | } |
| 166 | |
| 167 | // 验证池大小 |
| 168 | if pool.Size() != maxAgents { |
| 169 | t.Errorf("Expected pool size %d, got %d", maxAgents, pool.Size()) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // TestPool_List 测试列出 Agent |
| 174 | func TestPool_List(t *testing.T) { |
nothing calls this directly
no test coverage detected