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.
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package link
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type roomBus struct {
|
|
Bus
|
|
limit int64
|
|
sent [][]byte
|
|
}
|
|
|
|
func (b *roomBus) MaxPayload() int64 { return b.limit }
|
|
func (b *roomBus) PublishDeclaration(_ context.Context, _ string, body []byte) error {
|
|
b.sent = append(b.sent, body)
|
|
return nil
|
|
}
|
|
|
|
type fixedSigner struct{}
|
|
|
|
func (fixedSigner) Sign(context.Context, []byte) ([]byte, error) { return []byte("sig"), nil }
|
|
|
|
// A declaration is measured as it goes on the wire against the bus's own limit; one over it is refused saying size and
|
|
// limit, and what the measure sees is told to whoever raises a condition (issue 1689).
|
|
func TestADeclarationOverTheBusLimitIsRefusedSayingSizeAndLimit(t *testing.T) {
|
|
var seen []int64
|
|
was := DeclarationMeasured
|
|
DeclarationMeasured = func(_ context.Context, node string, size, limit int64) {
|
|
if node != "novox" || limit != 400 {
|
|
t.Errorf("measured %s against %d", node, limit)
|
|
}
|
|
seen = append(seen, size)
|
|
}
|
|
t.Cleanup(func() { DeclarationMeasured = was })
|
|
|
|
bus := &roomBus{limit: 400}
|
|
small := []byte(`{"a":"` + strings.Repeat("x", 100) + `"}`)
|
|
if err := Declare(t.Context(), bus, fixedSigner{}, "novox", small, time.Second); err != nil || len(bus.sent) != 1 {
|
|
t.Fatalf("a small declaration: %v, %d sent", err, len(bus.sent))
|
|
}
|
|
if int64(len(bus.sent[0])) != seen[0] {
|
|
t.Fatalf("measured %d bytes, sent %d", seen[0], len(bus.sent[0]))
|
|
}
|
|
|
|
big := []byte(`{"a":"` + strings.Repeat("x", 300) + `"}`)
|
|
err := Declare(t.Context(), bus, fixedSigner{}, "novox", big, time.Second)
|
|
if err == nil || !strings.Contains(err.Error(), "400 bytes") || !strings.Contains(err.Error(), "novox") ||
|
|
!strings.Contains(err.Error(), "over") || strings.Contains(err.Error(), "maximum payload exceeded") {
|
|
t.Fatalf("an oversize declaration: %v", err)
|
|
}
|
|
if len(bus.sent) != 1 || len(seen) != 2 || seen[1] <= 400 {
|
|
t.Fatalf("it was sent (%d) or not measured (%v)", len(bus.sent), seen)
|
|
}
|
|
}
|