Files
llmgw/internal/router/hardware_leader_test.go
T
Ilker ManapandClaude Opus 5.5 aa3efcebbe Add a standby control plane with server add, and draw the screens as windows
server add gives another machine this llmgw, a certificate, the
configuration and store address, lets it into the store through Patroni, and
starts it; --vip keeps a floating address on the leader with keepalived,
following a new /leader endpoint. Nodes learn every control plane from the
leader and notice a dead one by HTTP/2 ping instead of after the kernel's
fifteen minutes. The setup, console, node and init screens are drawn full
screen in one frame: title bar, sidebar, bordered panel, key bar, dialogs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-03 22:29:12 +02:00

44 lines
1.1 KiB
Go

package router
import (
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
)
func TestTheLeaderEndpointFollowsLeadership(t *testing.T) {
rt := newTestRouter(t, baseConfig())
get := func() int {
rec := httptest.NewRecorder()
rt.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/leader", nil))
return rec.Code
}
// No rival, nothing to follow: the one process leads.
if c := get(); c != http.StatusOK {
t.Errorf("with no leadership: %d", c)
}
leading := false
rt.SetLeader(func() bool { return leading })
if c := get(); c != http.StatusServiceUnavailable {
t.Errorf("a standby: %d", c)
}
leading = true
if c := get(); c != http.StatusOK {
t.Errorf("the leader: %d", c)
}
}
func TestTheLeaderEndpointNeedsNoKey(t *testing.T) {
// keepalived and load balancers ask it, and they have no key.
cfg := baseConfig()
cfg.Auth.Enabled = true
cfg.Auth.Store = filepath.Join(t.TempDir(), "store.db")
rt := newTestRouter(t, cfg)
rec := httptest.NewRecorder()
rt.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/leader", nil))
if rec.Code != http.StatusOK {
t.Errorf("/leader without a key: %d", rec.Code)
}
}