networkmanager: the uplink-names moments test waits on each call, not on the scheduler

The test changed check-address while the bundle, running beside it, had not yet read it
for its start's call. On a temporary directory in memory with one CPU, as a build step
runs, nothing yields before the test's write, so the start's call read the empty address
every time (pipeline main.517, asks mwvdrpjpbb0cf9 and mwvdrpjpb6c9b9); on a disk the
fsync yielded and it passed. The stood-in resolver now says each uplink-names call, and
the test changes the address only after the call before it.

Builds: design 08 sign-in-page §13, §25
This commit is contained in:
jochen
2026-11-25 01:37:04 +01:00
parent 5153e5fdc2
commit cd17899328
@@ -19,6 +19,8 @@ type fakeMesh struct {
fail error
calls []string
routes string
// given, when set, hears each uplink-names call once made, so a test acts after it and never on a guess of when.
given chan string
}
func (m *fakeMesh) ask(key string, body any) (json.RawMessage, error) {
@@ -38,6 +40,9 @@ func (m *fakeMesh) ask(key string, body any) (json.RawMessage, error) {
case "seat:node-resolver.uplink-names@laptop":
raw, _ := json.Marshal(body)
m.calls = append(m.calls, string(raw))
if m.given != nil {
m.given <- string(raw)
}
if m.fail != nil {
return nil, m.fail
}
@@ -66,10 +71,13 @@ func TestUplinkNamesIsCalledAtEachMoment(t *testing.T) {
if err := f.writeCheckAddress("http://Check.Example.net/connecttest"); err != nil {
t.Fatal(err)
}
mesh := &fakeMesh{holder: "systemd-resolved"}
mesh := &fakeMesh{holder: "systemd-resolved", given: make(chan string, 16)}
b := &bundle{folder: f, pub: &publisher{folder: f, publish: (&fakeStream{}).publish},
names: &namer{folder: f, ask: mesh.ask, now: time.Now}}
check := make(chan struct{})
// The bundle runs beside the test: each check address is changed only once the call made from the one before was
// heard, so the test never races the bundle's read of check-address (a call never made ends the run at its bound).
heard := func() { <-mesh.given }
var running func(stdio.Envelope) error
var hook func(stdio.Heartbeat)
done := make(chan struct{})
@@ -91,10 +99,12 @@ func TestUplinkNamesIsCalledAtEachMoment(t *testing.T) {
}})
close(done)
}()
heard()
if err := f.writeCheckAddress(""); err != nil {
t.Fatal(err)
}
check <- struct{}{}
heard()
f.writeCheckAddress("https://other.example.net/")
close(check)
<-done