36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|