mesh/merge-gate out of date: judged against trunk 5be1cfaed19b, the trunk is now f10fbda1f619; judged again on a recheck or when it is merged
mesh/repo-check out of date: judged against trunk 5be1cfaed19b, the trunk is now f10fbda1f619; judged again on a recheck or when it is merged
mesh/delivery delivered
A declaration is one bus message and the control node's passed the limit by 2 KB. The size is checked at every send against the connection's own limit, with a condition from 90% and a message naming size and limit when over; the export, 138 KB compact of 165 KB indented, is sent compact.
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
//go:build integration
|
|
|
|
package link
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
"github.com/novox/mesh-controller/internal/testbus"
|
|
)
|
|
|
|
// Against a real bus whose largest message is small: the limit is read from the connection, the one that fits goes
|
|
// through, the one over is refused by us with its size and the limit, not by the client's bare error (issue 1689).
|
|
func TestADeclarationIsMeasuredAgainstTheRealBusLimit(t *testing.T) {
|
|
s := testbus.StartWithMaxPayload(t, 2048)
|
|
conn, err := nats.Connect(s.ClientURL())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer conn.Close()
|
|
js, err := conn.JetStream()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := js.AddStream(&nats.StreamConfig{Name: "NODES", Subjects: []string{"mesh.node.*.declare"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
bus := OverNATS{Conn: conn, JS: js}
|
|
if bus.MaxPayload() != 2048 {
|
|
t.Fatalf("the limit read from the connection is %d, expected 2048", bus.MaxPayload())
|
|
}
|
|
var told []int64
|
|
was := DeclarationMeasured
|
|
DeclarationMeasured = func(_ context.Context, _ string, size, limit int64) { told = append(told, size, limit) }
|
|
t.Cleanup(func() { DeclarationMeasured = was })
|
|
|
|
fits := []byte(`{"a":"` + strings.Repeat("x", 600) + `"}`)
|
|
if err := Declare(t.Context(), bus, fixedSigner{}, "novox", fits, 5*time.Second); err != nil {
|
|
t.Fatalf("a declaration under the limit: %v", err)
|
|
}
|
|
over := []byte(`{"a":"` + strings.Repeat("x", 1600) + `"}`)
|
|
err = Declare(t.Context(), bus, fixedSigner{}, "novox", over, 5*time.Second)
|
|
if err == nil || !strings.Contains(err.Error(), "2048 bytes") || strings.Contains(err.Error(), "maximum payload exceeded") {
|
|
t.Fatalf("a declaration over the limit: %v", err)
|
|
}
|
|
if len(told) != 4 || told[1] != 2048 || told[2] <= 2048 {
|
|
t.Fatalf("measured %v", told)
|
|
}
|
|
}
|