45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package bus_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
|
"github.com/novox/mesh-tools/node-tools/internal/meshtest"
|
|
)
|
|
|
|
// novox/hq issue 314: a module's answer larger than the bus carries in one message is said to be too large,
|
|
// at once, not a 30-second silence. (The controller's paging ended with the controller, issue 1126.)
|
|
func TestAnAnswerLargerThanOneMessage(t *testing.T) {
|
|
url := meshtest.URL(t)
|
|
seat, err := nats.Connect(url)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer seat.Close()
|
|
c, err := bus.Connect(bus.Credential{URL: url, Module: "console", Node: "anchor"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
large := strings.Repeat("a condition held past its bound; ", 3*int(seat.MaxPayload())/32)
|
|
|
|
stop, err := c.HandleSubject("mesh.mod.journal.tool.lines", func(json.RawMessage) (any, error) { return large, nil })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer stop()
|
|
asked := time.Now()
|
|
_, err = c.Ask("journal.lines", map[string]any{}, "mesh.mod.journal.tool.lines")
|
|
if err == nil || !strings.Contains(err.Error(), "more than the bus carries") {
|
|
t.Fatalf("a module's answer too large for one message read as %v", err)
|
|
}
|
|
if took := time.Since(asked); took > 5*time.Second {
|
|
t.Fatalf("it took %s to say", took)
|
|
}
|
|
}
|