feat: improve channel resilience and operations

This commit is contained in:
hectorzhao
2026-07-24 08:17:33 +08:00
parent 2f781ebb8a
commit afd3c96070
43 changed files with 1969 additions and 299 deletions
+33
View File
@@ -140,6 +140,39 @@ func TestConnectChannelRejectsInvalidCommand(t *testing.T) {
}
}
func TestDisconnectChannelStopsSupplierPool(t *testing.T) {
var received DisconnectChannelCommand
handler := handlerWithServer(Server{
Disconnect: func(_ context.Context, command DisconnectChannelCommand) (ConnectionStateCallback, error) {
received = command
return ConnectionStateCallback{
ChannelID: command.ChannelID,
ConnectionID: command.ConnectionID,
Status: "disconnected",
CurrentConnections: 0,
}, nil
},
})
resp := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, "/connections/disconnect", strings.NewReader(`{
"schemaVersion":"v1",
"messageType":"DisconnectChannel",
"traceId":"trace-disconnect",
"channelId":"channel-1",
"connectionId":"channel-1:primary",
"reason":"channel_disabled"
}`))
handler.ServeHTTP(resp, req)
if resp.Code != http.StatusOK {
t.Fatalf("unexpected response status: %d body=%s", resp.Code, resp.Body.String())
}
if received.ChannelID != "channel-1" || received.Reason != "channel_disabled" {
t.Fatalf("unexpected disconnect command: %+v", received)
}
}
func TestRecoveryCandidatesEndpointReturnsView(t *testing.T) {
handler := handlerWithServer(Server{
RecoveryCandidates: func(context.Context) ([]inbound.DownstreamPresence, error) {