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>
44 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|