mesh/merge-gate head a5d3480e7e5d merged into trunk 59f8c9be0090 — pass: builds messenger → novox; no bus step; every machine composes with the change as i…
mesh/repo-check head a5d3480e7e5d merged into trunk 59f8c9be0090 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTheCapFollowsTheSetting(t *testing.T) {
|
|
h, tg, _, c, _ := newHolder(t)
|
|
h.Desk = nil
|
|
h.CapPerHour = func() int { return 3 }
|
|
for i := 0; i < 5; i++ {
|
|
h.Condition(EventRaised, cond(fmt.Sprintf("machine.m%d.silent", i), Urgent, "a machine is silent"))
|
|
c.pass(BurstWindow + time.Second)
|
|
h.Flush()
|
|
}
|
|
if len(tg.sends) != 4 || !strings.Contains(tg.sends[3].Body, "sent 3 messages") {
|
|
t.Fatalf("sent %d, want 3 and the cap said", len(tg.sends))
|
|
}
|
|
if cap := h.Status("listening").Channels[0].Cap; cap != 3 {
|
|
t.Fatalf("status cap %d", cap)
|
|
}
|
|
}
|
|
|
|
func TestMessagesPerHourIsReadFromTheSettingsFile(t *testing.T) {
|
|
read := func(body string) (Settings, error) {
|
|
p := filepath.Join(t.TempDir(), "settings.json")
|
|
if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return readSettings(p)
|
|
}
|
|
if s, err := read(`{"messages-per-hour": 100}`); err != nil || s.MessagesPerHour == nil || *s.MessagesPerHour != 100 {
|
|
t.Fatalf("set: %+v %v", s, err)
|
|
}
|
|
if s, err := read(`{"messages-per-hour": 0}`); err != nil || s.MessagesPerHour == nil || *s.MessagesPerHour != 0 {
|
|
t.Fatalf("zero: %+v %v", s, err)
|
|
}
|
|
if s, err := read(`{"time-zone": ""}`); err != nil || s.MessagesPerHour != nil {
|
|
t.Fatalf("unset: %+v %v", s, err)
|
|
}
|
|
}
|
|
|
|
// 0 turns the pause off (issue 1476): every message goes out and the pause is never said.
|
|
func TestACapOfZeroTurnsThePauseOff(t *testing.T) {
|
|
h, tg, _, c, _ := newHolder(t)
|
|
h.Desk = nil
|
|
h.CapPerHour = func() int { return 0 }
|
|
for i := 0; i < 500; i++ {
|
|
h.Condition(EventRaised, cond(fmt.Sprintf("machine.m%d.silent", i), Urgent, "a machine is silent"))
|
|
c.pass(BurstWindow + time.Second)
|
|
h.Flush()
|
|
}
|
|
if len(tg.sends) != 500 {
|
|
t.Fatalf("sent %d of 500", len(tg.sends))
|
|
}
|
|
for _, m := range tg.sends {
|
|
if strings.HasPrefix(m.Title, "Mesh messages paused") {
|
|
t.Fatalf("the pause was said with the cap off")
|
|
}
|
|
}
|
|
}
|