networkmanager: the watcher's health is its unit's state

The sign-in process is judged by its unit being active, on the machine without the bus,
and NetworkManager's service keeps no state and no health again. The watcher exits
non-zero when it cannot subscribe once the system bus came back, so its unit shows
failing; uplink_health stays a tool that reads and no longer gives the names again.

Builds: design 08 sign-in-page §11, §13, §14, §23, §24, §25, §27; lead answer C-2c (hq 6752a5cf)
This commit is contained in:
jochen
2026-11-24 21:53:29 +01:00
parent 55a90d963e
commit 397e627b02
9 changed files with 59 additions and 80 deletions
@@ -305,7 +305,7 @@ func TestTheWatcherSubscribesAgainAndRunsOnNoTimer(t *testing.T) {
w := aWatcher(t, sys)
stop := make(chan struct{})
done := make(chan struct{})
go func() { w.run(stop); close(done) }()
go func() { _ = w.run(stop); close(done) }()
defer func() { close(stop); <-done }()
state := func() watcherState {
s, err := w.askLoop(askState)
@@ -393,15 +393,15 @@ func TestTheWatcherHearsTheSystemBusSignals(t *testing.T) {
}
// The watcher dials the system bus again only at the file event that makes its socket and at rating-again, never in a
// loop: a bus that refuses it, at its start or after a drop, is not dialled again until one of the two (§14; note d).
// loop (§14; note d); and when the bus came back and it cannot subscribe on it, it ends with an error, so its process
// exits non-zero and its unit shows failing (§11; lead answer C-2c).
func TestTheWatcherRedialsOnlyAtTheSocketsEventAndRatingAgain(t *testing.T) {
journalLines(t)
sys := &fakeSystem{socket: make(chan struct{}), refuse: 1}
sys.set(guest(ratingFull))
w := aWatcher(t, sys)
stop, done := make(chan struct{}), make(chan struct{})
go func() { w.run(stop); close(done) }()
defer func() { close(stop); <-done }()
stop, done := make(chan struct{}), make(chan error, 1)
go func() { done <- w.run(stop) }()
state := func() watcherState {
s, _ := w.askLoop(askState)
return s.(watcherState)
@@ -413,32 +413,30 @@ func TestTheWatcherRedialsOnlyAtTheSocketsEventAndRatingAgain(t *testing.T) {
}
}
if d := dials(); d != 1 {
t.Fatalf("a refused bus was dialled %d times with no event", d)
t.Fatalf("a bus that refused the watcher at its start was dialled %d times with no event", d)
}
sys.socket <- struct{}{}
if s := state(); !s.Subscribed || dials() != 2 {
t.Fatalf("at the socket's event: %+v, %d dials", s, dials())
}
close(sys.last().signals)
state()
state()
if d := dials(); d != 2 {
t.Fatalf("a dropped connection was dialled again before the socket's event: %d dials", d)
}
if _, err := w.askLoop(askRatingAgain); err != nil || dials() != 3 || !state().Subscribed {
t.Fatalf("rating-again: %v, %d dials", err, dials())
}
close(sys.last().signals)
sys.mu.Lock()
sys.refuse = 1
sys.mu.Unlock()
sys.socket <- struct{}{}
state()
if d := dials(); d != 2 || state().Subscribed {
t.Fatalf("at the socket's event: %d dials", d)
}
state()
if d := dials(); d != 2 {
t.Fatalf("dialled again with no event: %d dials", d)
}
sys.socket <- struct{}{}
if s := state(); !s.Subscribed || dials() != 3 {
t.Fatalf("at the next socket event: %+v, %d dials", s, dials())
}
close(sys.last().signals)
state()
if d := dials(); d != 3 {
t.Fatalf("a dropped connection was dialled again before the socket's event: %d dials", d)
}
if _, err := w.askLoop(askRatingAgain); err != nil || dials() != 4 || !state().Subscribed {
t.Fatalf("rating-again: %v, %d dials", err, dials())
if err := <-done; err == nil || !strings.Contains(err.Error(), "could not subscribe") || dials() != 4 {
t.Fatalf("the bus came back refusing: the watcher ended with %v after %d dials", err, dials())
}
close(stop)
}
// The real wait fires at the file event that makes the system bus's socket, not for one that is merely there (note d).