H2b-review-3 journal-lines-asserted: the hub rows assert the journal lines through logf, and a process reader row adopts an event after the hub's Start
Builds: design 47 H2b §836 4. (review round 1, part 1, item 3)
This commit is contained in:
@@ -492,9 +492,22 @@ func subTheHubStartBindsEveryPatternAndSaysWhenAllAreHeard(t *testing.T) {
|
||||
kept := "SEAT_node-engine_running"
|
||||
cred := Account{Node: "n1", Module: "teller"}
|
||||
var unheardTold [][]Unheard // what OnUnheard was told, in order (1984/AC-836e)
|
||||
var jmu sync.Mutex
|
||||
var journal []string // the hub's journal lines (1984/AC-836r, AC-836s)
|
||||
logf := func(f string, a ...any) {
|
||||
jmu.Lock()
|
||||
journal = append(journal, fmt.Sprintf(f, a...))
|
||||
jmu.Unlock()
|
||||
t.Logf(f, a...)
|
||||
}
|
||||
said := func(want string) bool {
|
||||
jmu.Lock()
|
||||
defer jmu.Unlock()
|
||||
return slices.ContainsFunc(journal, func(l string) bool { return strings.Contains(l, want) })
|
||||
}
|
||||
newHub := func(bus *fakeHubBus) (h *EventHub, allHeard *int, created *[]time.Time) {
|
||||
h, allHeard, created = NewEventHub(t.Logf), new(int), new([]time.Time)
|
||||
unheardTold = nil
|
||||
h, allHeard, created = NewEventHub(logf), new(int), new([]time.Time)
|
||||
unheardTold, journal = nil, nil
|
||||
h.OnUnheard(func(list []Unheard) { unheardTold = append(unheardTold, list) })
|
||||
h.OnAllHeard(func() { *allHeard++ })
|
||||
h.OnBound(func(at time.Time) { *created = append(*created, at) })
|
||||
@@ -542,6 +555,9 @@ func subTheHubStartBindsEveryPatternAndSaysWhenAllAreHeard(t *testing.T) {
|
||||
if *allHeard != 0 || len(h.unheardNow) != 1 || h.unheardNow[0].Stream != kept || !strings.Contains(h.unheardNow[0].Why, "not composed") {
|
||||
t.Fatalf("all heard %d, unheard %+v", *allHeard, h.unheardNow)
|
||||
}
|
||||
if !said("the pattern mesh.seat.node-engine.event.running.> is not heard on " + kept + ": not composed") {
|
||||
t.Errorf("the journal names no pattern not heard: %q", journal)
|
||||
}
|
||||
bus.composed[kept] = errors.New("the bus refuses")
|
||||
bus.onWake()
|
||||
if *allHeard != 0 || !strings.Contains(h.unheardNow[0].Why, "refused") {
|
||||
@@ -565,6 +581,9 @@ func subTheHubStartBindsEveryPatternAndSaysWhenAllAreHeard(t *testing.T) {
|
||||
if n := len(unheardTold); n != 4 || len(unheardTold[3]) != 1 || unheardTold[3][0] != (Unheard{"mesh.mod.p.event.late", "", "registered after Start"}) {
|
||||
t.Errorf("OnUnheard was told %v", unheardTold)
|
||||
}
|
||||
if !said("the pattern mesh.mod.p.event.late is not heard: registered after Start") {
|
||||
t.Errorf("the journal says nothing of the pattern refused after Start: %q", journal)
|
||||
}
|
||||
})
|
||||
// AC-836b clause 2: the wake is made before the first bind, so the word that the durables were composed, said from inside
|
||||
// Start's own failing bind, binds the stream.
|
||||
@@ -606,5 +625,8 @@ func subTheHubStartBindsEveryPatternAndSaysWhenAllAreHeard(t *testing.T) {
|
||||
if *allHeard != 0 || len(h.unheardNow) != 1 || h.unheardNow[0].Pattern != "mesh.mod.p.event.x" || h.unheardNow[0].Why != "no stream carries it" {
|
||||
t.Errorf("all heard %d, unheard %+v", *allHeard, h.unheardNow)
|
||||
}
|
||||
if !said("the pattern mesh.mod.p.event.x is not heard: no stream carries it") {
|
||||
t.Errorf("the journal names no pattern no stream carries: %q", journal)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -410,6 +411,22 @@ func subAHandlingPastEventOverrunRaisesItsFindingAndTheNextStartClearsIt(t *test
|
||||
if got := <-found.cleared; got != "events-unheard reader=2en1" {
|
||||
t.Fatalf("the hub's start cleared %s", got)
|
||||
}
|
||||
// design 47 H2b §836 3., 4. (1984/AC-836s): an event adopted after the hub's Start is refused, said in the module's journal,
|
||||
// and raises events-unheard naming its pattern
|
||||
var mu sync.Mutex
|
||||
var lines []string
|
||||
r.Logf = func(f string, a ...any) { mu.Lock(); lines = append(lines, fmt.Sprintf(f, a...)); mu.Unlock() }
|
||||
if err := r.AdoptEvent("s", "late", func(context.Context, []byte) error { return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := <-found.put; !strings.HasPrefix(got, "events-unheard ") || !strings.Contains(got, "mesh.seat.s.event.late") || !strings.Contains(got, "registered after Start") {
|
||||
t.Fatalf("the event adopted after Start raised %s", got)
|
||||
}
|
||||
mu.Lock()
|
||||
if len(lines) != 1 || !strings.Contains(lines[0], "mesh.seat.s.event.late is not heard") {
|
||||
t.Errorf("the reader's journal: %q", lines)
|
||||
}
|
||||
mu.Unlock()
|
||||
if _, err := js.Publish(ctx, "mesh.mod.p.event.slow", []byte("{}")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user