diff --git a/internal/http2/integration_tls_test.go b/internal/http2/integration_tls_test.go index 5342948..49e7577 100644 --- a/internal/http2/integration_tls_test.go +++ b/internal/http2/integration_tls_test.go @@ -431,25 +431,25 @@ func TestConnectionPoolOperations(t *testing.T) { pool.add("client1", conn2) // 验证连接数 - if count := pool.count("client1"); count != 2 { + if count := len(pool.conns["client1"]); count != 2 { t.Errorf("Expected 2 connections, got %d", count) } // 获取连接 - conns := pool.get("client1") + conns := pool.conns["client1"] if len(conns) != 2 { t.Errorf("Expected 2 connections, got %d", len(conns)) } // 移除连接 pool.remove("client1", conn1) - if count := pool.count("client1"); count != 1 { + if count := len(pool.conns["client1"]); count != 1 { t.Errorf("Expected 1 connection after removal, got %d", count) } // 关闭所有连接 pool.closeAll() - if count := pool.count("client1"); count != 0 { + if count := len(pool.conns["client1"]); count != 0 { t.Errorf("Expected 0 connections after closeAll, got %d", count) } } diff --git a/internal/http2/server.go b/internal/http2/server.go index 7890455..6e6a53d 100644 --- a/internal/http2/server.go +++ b/internal/http2/server.go @@ -572,20 +572,6 @@ func (p *connectionPool) remove(key string, conn net.Conn) { } } -// get 获取连接。 -func (p *connectionPool) get(key string) []net.Conn { - p.mu.RLock() - defer p.mu.RUnlock() - return p.conns[key] -} - -// count 获取连接数。 -func (p *connectionPool) count(key string) int { - p.mu.RLock() - defer p.mu.RUnlock() - return len(p.conns[key]) -} - // closeAll 关闭所有连接。 func (p *connectionPool) closeAll() { p.mu.Lock() diff --git a/internal/http2/server_test.go b/internal/http2/server_test.go index ade01b0..0a887d9 100644 --- a/internal/http2/server_test.go +++ b/internal/http2/server_test.go @@ -444,19 +444,19 @@ func TestConnectionPool(t *testing.T) { pool.add("key1", conn1) // 测试获取连接 - conns := pool.get("key1") + conns := pool.conns["key1"] if len(conns) != 1 { t.Errorf("Expected 1 connection, got %d", len(conns)) } // 测试计数 - if count := pool.count("key1"); count != 1 { + if count := len(pool.conns["key1"]); count != 1 { t.Errorf("Expected count 1, got %d", count) } // 测试移除连接 pool.remove("key1", conn1) - if count := pool.count("key1"); count != 0 { + if count := len(pool.conns["key1"]); count != 0 { t.Errorf("Expected count 0 after remove, got %d", count) } } @@ -953,7 +953,7 @@ func TestConnectionPool_CloseAll(t *testing.T) { pool.closeAll() // 验证连接池已清空 - if count := pool.count("key1"); count != 0 { + if count := len(pool.conns["key1"]); count != 0 { t.Errorf("Expected count 0 after closeAll, got %d", count) } }