node-tools: the unanswered end of the seat list's first read is said also when it ends after the bound (A-490m)
Builds: design 47 G A-490m Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -63,17 +63,25 @@ func startSeatListOn(b seatlist.Bus, bound <-chan time.Time, logf func(string, .
|
||||
return nil
|
||||
}
|
||||
catalogue.UseSeats(reader.Seats())
|
||||
// a first read that ended without an answer is no failure of the reader, which holds the bootstrap and waits for the seat's next
|
||||
// event: so it is said here, where nothing else would say it, whether it ends before the bound or after it (a read the bus does
|
||||
// not answer is asked again for about 30 s, so it ends after the bound); the runner then reads again where a bundle asks a verb of
|
||||
// a seat the list defines that its definition does not name (design 47 G A-490m)
|
||||
sayUnanswered := func() {
|
||||
if st := reader.Status(); !st.Heard {
|
||||
logf("node-tools: the first read of the seat list ended without an answer (%s); the runner serves with the bootstrapped seats and reads again when a bundle asks a verb of a seat the list defines that its definition does not name", st.LastError)
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-reader.Ready():
|
||||
catalogue.UseSeats(reader.Seats())
|
||||
// a first read that ended without an answer is no failure of the reader, which holds the bootstrap and waits for the seat's
|
||||
// next event: so it is said here, where nothing else would say it (the runner then reads again where a bundle asks a verb
|
||||
// its definitions do not name)
|
||||
if st := reader.Status(); !st.Heard {
|
||||
logf("node-tools: the first read of the seat list ended without an answer (%s); the runner serves with the bootstrapped seats and reads again when a bundle asks a verb they do not name", st.LastError)
|
||||
}
|
||||
sayUnanswered()
|
||||
case <-bound:
|
||||
logf("node-tools: the seat list is not read yet; the runner serves with the bootstrapped seats and reads on")
|
||||
go func() {
|
||||
<-reader.Ready()
|
||||
sayUnanswered()
|
||||
}()
|
||||
}
|
||||
return reader
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -34,17 +35,21 @@ func TestTheRunnerWaitsForTheFirstReadOfTheSeatListOnlyToItsBound(t *testing.T)
|
||||
}{
|
||||
{"the first read ends before the bound, unanswered", true, "the first read of the seat list ended without an answer", true},
|
||||
{"the bound passes with the seat silent", false, "the seat list is not read yet", false},
|
||||
{"the bound passes, then the read ends unanswered", false, "the first read of the seat list ended without an answer", false},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
b := &busOfAStandIn{release: make(chan struct{})}
|
||||
bound := make(chan time.Time, 1)
|
||||
var mu sync.Mutex
|
||||
var said []string
|
||||
saidAgain := make(chan struct{}, 4)
|
||||
say := func(f string, a ...any) { mu.Lock(); said = append(said, f); mu.Unlock(); saidAgain <- struct{}{} }
|
||||
if row.release {
|
||||
close(b.release)
|
||||
} else {
|
||||
bound <- time.Time{}
|
||||
}
|
||||
r := startSeatListOn(b, bound, func(f string, a ...any) { said = append(said, f) })
|
||||
r := startSeatListOn(b, bound, say)
|
||||
if r == nil {
|
||||
t.Fatal("no reader")
|
||||
}
|
||||
@@ -57,12 +62,25 @@ func TestTheRunnerWaitsForTheFirstReadOfTheSeatListOnlyToItsBound(t *testing.T)
|
||||
if ended != row.wantReady {
|
||||
t.Errorf("first read ended = %v, want %v", ended, row.wantReady)
|
||||
}
|
||||
if got := strings.Join(said, ";"); !strings.Contains(got, row.wantSaid) {
|
||||
t.Errorf("said %q, want %q", got, row.wantSaid)
|
||||
}
|
||||
if !row.release {
|
||||
close(b.release)
|
||||
<-r.Ready()
|
||||
// the read that ends after the bound is said by a goroutine of its own: wait for it, to a deadline that only a fault reaches
|
||||
if strings.Contains(row.wantSaid, "first read") {
|
||||
for i := 0; i < 2; i++ {
|
||||
select {
|
||||
case <-saidAgain:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the unanswered end of the first read was never said")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mu.Lock()
|
||||
got := strings.Join(said, ";")
|
||||
mu.Unlock()
|
||||
if !strings.Contains(got, row.wantSaid) {
|
||||
t.Errorf("said %q, want %q", got, row.wantSaid)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user