ipc: promote startup socket-wait to a shared DialWait; use in all modules
The cold-start crash-loop wasn't mavweb-specific — mavpoll and mavcaldav also ipc.Dial + exit on failure, so they crash-looped until core booted too. Moved the retry into ipc.DialWait (capped backoff, bounded) and switched mavweb, mavpoll, mavcaldav to it. mavweb's local dialCoreWithRetry is gone. Test: server appears after DialWait starts → it waits and connects. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,46 @@ func newServerWithStore(t *testing.T) (CoreAPI, *Server, *Client, *store.Store)
|
||||
return api, srv, cli, s
|
||||
}
|
||||
|
||||
// TestDialWait_WaitsForLateServer — a module may start before core's socket
|
||||
// exists (core loads models first). DialWait must keep retrying until the
|
||||
// socket appears rather than fail on the first attempt.
|
||||
func TestDialWait_WaitsForLateServer(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sock := filepath.Join(dir, "maven.sock")
|
||||
srvCh := make(chan *Server, 1)
|
||||
errCh := make(chan error, 1)
|
||||
|
||||
// bring the server up only after DialWait is already retrying
|
||||
go func() {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
s, err := store.Open(context.Background(), filepath.Join(dir, "maven.db"))
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
t.Cleanup(func() { _ = s.Close() })
|
||||
srv, err := Listen(sock, NewStoreAPI(s))
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
go func() { _ = srv.Serve() }()
|
||||
srvCh <- srv
|
||||
}()
|
||||
|
||||
cli, err := DialWait(sock, 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("DialWait should connect once the server appears: %v", err)
|
||||
}
|
||||
select {
|
||||
case err := <-errCh:
|
||||
t.Fatalf("server setup failed: %v", err)
|
||||
case srv := <-srvCh:
|
||||
_ = cli.Close() // close client first so srv.Close's handler wait returns
|
||||
_ = srv.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// TestClient_ReconnectsAfterServerRestart — a long-lived module (e.g. mavweb)
|
||||
// must survive a core restart. The first server is closed and a new one is
|
||||
// brought up on the SAME socket path (as a daemon restart does); the client's
|
||||
|
||||
Reference in New Issue
Block a user