feat: complete cmpp gateway delivery recovery workflows
This commit is contained in:
@@ -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",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user