The queue asks a tool through a ToolBus assertion that only OverNATS satisfied; the link the engine actually holds (natsLink) had no Ask, so every tool check failed as "no link to the bus is open" while the link was up (hq issue 331). Give natsLink Ask, assert at build time every optional interface the queue expects of it, and tell a link that cannot ask apart from no link.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package link
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
// A declared tool check asked over a real bus, through the queue, on the link the node-engine holds:
|
|
// the tool's answer is read, and a tool nothing serves is said as such (novox/hq ADR 0240, to-be 48 §3).
|
|
func TestNatsAToolCheckIsAskedOnTheLink(t *testing.T) {
|
|
conn, js := aBus(t)
|
|
const node = "toolcheck"
|
|
served, err := conn.Subscribe(ToolSubject("sensors", "sensors_health", node), func(m *nats.Msg) {
|
|
_ = m.Respond([]byte(`{"result":{"healthy":true}}`))
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = served.Unsubscribe() })
|
|
if err := conn.Flush(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
q := &Queue{Membership: Membership{Node: node}}
|
|
q.attach(t.Context(), &natsLink{conn: conn, js: js, node: node})
|
|
ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second)
|
|
defer cancel()
|
|
healthy, why, err := q.AskTool(ctx, "sensors", "sensors_health")
|
|
if err != nil || !healthy {
|
|
t.Fatalf("a served healthy tool read as %v %q (%v)", healthy, why, err)
|
|
}
|
|
_, _, err = q.AskTool(ctx, "sensors", "nothing_serves_this")
|
|
if err == nil || !strings.Contains(err.Error(), "nothing on this machine answers") {
|
|
t.Fatalf("a tool nothing serves read as %v", err)
|
|
}
|
|
}
|