feat: improve channel resilience and operations
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package upstream
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"cmpp-platform/gateway/internal/queue"
|
||||
@@ -39,6 +40,38 @@ func TestConnectionPoolAcquiresAcrossConnections(t *testing.T) {
|
||||
releaseSecond()
|
||||
}
|
||||
|
||||
func TestManagerDisconnectChannelRemovesPoolAndStopsReconnects(t *testing.T) {
|
||||
pool := &connectionPool{
|
||||
channelID: "channel-1",
|
||||
connectionID: "channel-1:primary",
|
||||
config: normalizeUpstreamConfig(queueUpstreamConfigForTest()),
|
||||
reconnectSignal: make(chan struct{}, 1),
|
||||
stopCh: make(chan struct{}),
|
||||
}
|
||||
manager := &Manager{conns: map[string]*connectionPool{"channel-1": pool}}
|
||||
|
||||
state, err := manager.DisconnectChannel(context.Background(), queue.DisconnectChannelCommand{
|
||||
MessageType: queue.MessageTypeDisconnectChannel,
|
||||
ChannelID: "channel-1",
|
||||
ConnectionID: "channel-1:primary",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("disconnect channel: %v", err)
|
||||
}
|
||||
if state.Status != "disconnected" || state.CurrentConnections != 0 {
|
||||
t.Fatalf("unexpected state: %+v", state)
|
||||
}
|
||||
if _, exists := manager.conns["channel-1"]; exists {
|
||||
t.Fatal("expected channel pool to be removed")
|
||||
}
|
||||
select {
|
||||
case <-pool.stopCh:
|
||||
default:
|
||||
t.Fatal("expected reconnect supervisor to be stopped")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeUpstreamConfigDefaults(t *testing.T) {
|
||||
config := normalizeUpstreamConfig(queueUpstreamConfigForTest())
|
||||
if config.DesiredConnections != 1 {
|
||||
@@ -47,6 +80,9 @@ func TestNormalizeUpstreamConfigDefaults(t *testing.T) {
|
||||
if config.WindowSize != defaultWindowSize {
|
||||
t.Fatalf("WindowSize = %d, want %d", config.WindowSize, defaultWindowSize)
|
||||
}
|
||||
if config.HeartbeatIntervalSeconds != 30 || config.HeartbeatMissThreshold != 3 {
|
||||
t.Fatalf("unexpected heartbeat defaults: interval=%d threshold=%d", config.HeartbeatIntervalSeconds, config.HeartbeatMissThreshold)
|
||||
}
|
||||
}
|
||||
|
||||
func queueUpstreamConfigForTest() queue.UpstreamConfig {
|
||||
|
||||
Reference in New Issue
Block a user