feat: complete cmpp gateway delivery recovery workflows

This commit is contained in:
hectorzhao
2026-07-08 16:30:06 +08:00
parent cc628d0214
commit 8144f08652
60 changed files with 8901 additions and 94 deletions
+60
View File
@@ -0,0 +1,60 @@
package upstream
import (
"testing"
"cmpp-platform/gateway/internal/queue"
)
func TestConnectionPoolAcquiresAcrossConnections(t *testing.T) {
pool := &connectionPool{
conns: []*connection{
{window: make(chan struct{}, 1)},
{window: make(chan struct{}, 1)},
},
}
first, releaseFirst := pool.tryAcquireConnection()
if first == nil {
t.Fatalf("expected first connection")
}
second, releaseSecond := pool.tryAcquireConnection()
if second == nil {
t.Fatalf("expected second connection")
}
if first == second {
t.Fatalf("expected pool to use another connection when the first window is full")
}
third, _ := pool.tryAcquireConnection()
if third != nil {
t.Fatalf("expected nil connection while all windows are full")
}
releaseFirst()
reacquired, releaseReacquired := pool.tryAcquireConnection()
if reacquired == nil {
t.Fatalf("expected a connection after releasing a window")
}
releaseReacquired()
releaseSecond()
}
func TestNormalizeUpstreamConfigDefaults(t *testing.T) {
config := normalizeUpstreamConfig(queueUpstreamConfigForTest())
if config.DesiredConnections != 1 {
t.Fatalf("DesiredConnections = %d, want 1", config.DesiredConnections)
}
if config.WindowSize != defaultWindowSize {
t.Fatalf("WindowSize = %d, want %d", config.WindowSize, defaultWindowSize)
}
}
func queueUpstreamConfigForTest() queue.UpstreamConfig {
return queue.UpstreamConfig{
GatewayHost: "127.0.0.1",
GatewayPort: 17890,
Account: "account",
PasswordCipher: "secret",
CMPPVersion: "3.0",
}
}