fix: harden multi-pod delivery and load verification

This commit is contained in:
richjohnrambo
2026-09-27 03:37:32 +08:00
parent a2de100f2b
commit ce3250be64
33 changed files with 1340 additions and 94 deletions
+35
View File
@@ -0,0 +1,35 @@
package main
import (
"errors"
"net/http"
"testing"
"time"
"github.com/tinode/chat/server/store/types"
)
func TestClusterReqShardIsStablePerTenantTopic(t *testing.T) {
req := &ClusterReq{TenantID: types.TenantID(6), RcptTo: "p2p-topic"}
want := clusterReqShard(req, 16)
for i := 0; i < 100; i++ {
if got := clusterReqShard(req, 16); got != want {
t.Fatalf("unstable shard: got=%d want=%d", got, want)
}
}
if got := clusterReqShard(req, 1); got != 0 {
t.Fatalf("single worker shard=%d", got)
}
}
func TestClusterRouteErrorReplySeparatesOverloadFromDisconnect(t *testing.T) {
msg := &ClientComMessage{Id: "test", Timestamp: time.Now()}
overload := clusterRouteErrorReply(msg, errClusterLoadExceeded)
if overload.Ctrl == nil || overload.Ctrl.Code != http.StatusServiceUnavailable || overload.Ctrl.Text != "cluster overloaded" {
t.Fatalf("unexpected overload reply: %+v", overload.Ctrl)
}
disconnected := clusterRouteErrorReply(msg, errors.New("disconnected"))
if disconnected.Ctrl == nil || disconnected.Ctrl.Code != http.StatusBadGateway {
t.Fatalf("unexpected disconnected reply: %+v", disconnected.Ctrl)
}
}