Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ require (
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect

replace pico2-a-b => ../pico2-a-b

replace github.com/jangala-dev/tinygo-uartx => ./third_party/tinygo-uartx
25 changes: 24 additions & 1 deletion services/fabric/fabric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ func pipePair() (*rwTransport, *rwTransport) {

func newBus() *bus.Bus { return bus.NewBus(3, "+", "#") }

func TestShouldLogFabricReadSkipsIdleDataFrames(t *testing.T) {
longRead := 3 * time.Second
longGap := 3 * time.Second

for _, msgType := range []string{msgPub, msgPing, msgPong, msgUnretain} {
if shouldLogFabricRead(msgType, longRead, longGap) {
t.Fatalf("idle %s frame should not be logged", msgType)
}
}

for _, msgType := range []string{msgHello, msgHelloAck, msgCall, msgReply, msgXferBegin, msgXferCommit, msgXferAbort} {
if !shouldLogFabricRead(msgType, 0, 0) {
t.Fatalf("control %s frame should be logged", msgType)
}
}
}

type captureTransport struct {
writes [][]byte
writeErr error
Expand Down Expand Up @@ -1995,6 +2012,7 @@ func TestCallIgnoredBeforeHandshake(t *testing.T) {
func TestCallImport(t *testing.T) {
// Test the canonical inbound call route: cap/self/updater/main/rpc/prepare-update
// maps to local rpc/updater/prepare where services/updater binds.
diag := captureOTADiag(t)
mcu, cm5 := pipePair()
b := newBus()
fabricConn := b.NewConnection("fabric")
Expand All @@ -2013,7 +2031,7 @@ func TestCallImport(t *testing.T) {

sendMsg(t, cm5, protoCall{
Type: "call", ID: "test-corr-1", Topic: []string{"cap", "self", "updater", "main", "rpc", "prepare-update"},
Payload: json.RawMessage(`{}`), TimeoutMs: 5000,
Payload: json.RawMessage(`{"job_id":"job-prepare","expected_image_id":"mcu-dev-15.3"}`), TimeoutMs: 5000,
})

reply := readMsg[protoReply](t, cm5)
Expand All @@ -2023,6 +2041,11 @@ func TestCallImport(t *testing.T) {
if !reply.OK {
t.Errorf("reply not ok: %s", reply.Err)
}
lines := diag.snapshot()
assertDiagContains(t, lines, "[fabric-rpc]", "ev call_rx", "call_id test-corr-1", "job_id job-prepare", "expected_image_id mcu-dev-15.3")
assertDiagContains(t, lines, "[fabric-rpc]", "ev call_route_ok", "local_topic rpc/updater/prepare")
assertDiagContains(t, lines, "[fabric-rpc]", "ev call_dispatch_start", "timeout_ms 5000")
waitDiagContains(t, diag, "[fabric-rpc]", "ev call_reply_tx", "ok true", "sent true")
}

func TestCallNoRoute(t *testing.T) {
Expand Down
Loading