64 lines
2.6 KiB
Go
64 lines
2.6 KiB
Go
package main
|
||
|
||
import (
|
||
"encoding/json"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/novox/mesh-controller/internal/conditions"
|
||
)
|
||
|
||
// The serving controller's own connection serves what it does for a moment: no connection is opened,
|
||
// and closing what it was lent leaves the serving one open (novox/hq issue 327).
|
||
|
||
// A verb that still runs as a process of its own says which in the bus's list of connections.
|
||
|
||
func TestEachProcessNamesItsConnectionsForWhatItIs(t *testing.T) {
|
||
for _, c := range []struct{ command, verb, want string }{
|
||
{"serve", "", "mesh-controller serving"},
|
||
{"conditions", "conditions", "mesh-controller verb conditions"},
|
||
{"delivery", "delivery-check", "mesh-controller verb delivery-check"},
|
||
{"push", "", "mesh-controller command push"},
|
||
} {
|
||
if got := connectionName(c.command, c.verb); got != c.want {
|
||
t.Errorf("%s/%s: %q", c.command, c.verb, got)
|
||
}
|
||
}
|
||
}
|
||
|
||
// D15: a user whose connections are dropped more than twelve times an hour is said, in plain words; one
|
||
// whose client closes its own short connections is not.
|
||
func TestAClientReconnectingInALoopIsSaid(t *testing.T) {
|
||
var read closedConnections
|
||
if err := json.Unmarshal([]byte(`{"hours":1,"reaches":true,"users":[
|
||
{"user":"ace.node-tools","closed":40,"dropped":40,"dropped_per_hour":40,"names":[
|
||
{"name":"ace.node-tools","closed":40,"dropped":40,"reasons":{"Stale Connection":30,"Read Error":10}}]},
|
||
{"user":"controller","closed":300,"dropped":0,"names":[
|
||
{"name":"mesh-controller verb delivery-check","closed":300,"dropped":0,"reasons":{"Client Closed":300}}]},
|
||
{"user":"(no user: refused before it logged in)","closed":90,"dropped":90,"names":[{"name":"","closed":90,
|
||
"dropped":90,"reasons":{"Authentication Failure":90}}]},
|
||
{"user":"node.anchor","closed":5,"dropped":5,"names":[{"name":"mesh-host/anchor","closed":5,"dropped":5,
|
||
"reasons":{"Read Error":5}}]}]}`), &read); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
found := reconnecting(read)
|
||
if len(found) != 1 {
|
||
t.Fatalf("%+v", found)
|
||
}
|
||
o := found[0]
|
||
if o.ID != "ace.node-tools" || o.Machine != "ace" || o.Kind != kindBusReconnects ||
|
||
o.Headline != "The tool runner on ace keeps losing the bus" || !strings.Contains(o.Said, "Stale Connection ×30") {
|
||
t.Fatalf("%+v", o)
|
||
}
|
||
if why, ok := conditions.PlainWords(conditions.Words{Headline: o.Headline, Explanation: o.Explanation,
|
||
Resolved: o.Resolved}, "ace"); !ok {
|
||
t.Fatalf("not plain: %s", why)
|
||
}
|
||
}
|
||
|
||
// The bus's module is asked on its machine, over the bus.
|
||
|
||
// A bus module older than the tool answers nothing to the question: the probe passes over it quietly.
|
||
|
||
// A verb answered in the serving controller says its flag errors in its answer, not in the controller's log.
|