Builds: design 47 G §59, §407 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
//go:build integration
|
|
|
|
package stateobjects
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/testbus"
|
|
)
|
|
|
|
// ADR 0666 §16, §25 against the real bus: a process's values of 1x, 10x and 100x the limit, replaced and deleted, and a
|
|
// body over the per-message limit sent and received, each read back whole.
|
|
func TestStateObjectsWholeAgainstTheBus(t *testing.T) {
|
|
nc, err := nats.Connect(testbus.URL(t))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer nc.Close()
|
|
js, err := jetstream.New(nc)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "m_views", MaxValueSize: 256 * 1024, Storage: jetstream.MemoryStorage})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
store, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "m_views-objects", Storage: jetstream.MemoryStorage})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sent, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "m_sent-objects", Storage: jetstream.MemoryStorage, TTL: 7 * 24 * time.Hour})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Run("a reply and an event over the message limit", func(t *testing.T) {
|
|
s := Sender{Objects: BusObjects{Store: sent}, Store: "m_sent-objects", Limit: int(nc.MaxPayload())}
|
|
for _, label := range []string{"reply.list", "event.done"} {
|
|
body := []byte(`{"text":"` + strings.Repeat("y", 3<<20) + `"}`)
|
|
wire, err := s.Send(label, body)
|
|
if err != nil || len(wire) > int(nc.MaxPayload()) {
|
|
t.Fatalf("%s: sent %d bytes, %v", label, len(wire), err)
|
|
}
|
|
got, err := Receive(wire, ProcessFetch(BusObjects{Store: sent}))
|
|
if err != nil || !bytes.Equal(got, body) {
|
|
t.Fatalf("%s: received %d bytes, %v", label, len(got), err)
|
|
}
|
|
}
|
|
})
|
|
t.Run("values of 1x, 10x and 100x the limit", func(t *testing.T) { valueRows(t, OverBus(kv, store, "m_views-objects")) })
|
|
}
|