Phase 13, part 9: running at scale, and the proof

The multi-tenant edition starts. compose.multi.yaml runs several copies
behind Caddy, with the managed Postgres and Garage outside. A test walks
every page and fragment, with ids filled in, and every MCP tool, as one
team, and none shows another team's data or changes it; another has three
copies share six teams' work, each team's turn once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:46:01 -07:00
co-authored by Claude Opus 5.5
parent b8a64e258a
commit f4c31c9fa3
13 changed files with 453 additions and 14 deletions
+66
View File
@@ -11,6 +11,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"testing"
"time"
@@ -551,3 +552,68 @@ func sessionIn(t *testing.T, s *Server, u *users.User, team int64) *http.Cookie
}
return &http.Cookie{Name: sessionCookie, Value: tok}
}
// Three copies of the app, behind a load balancer, share the teams' work:
// each team's turn runs once, and the copies each take some.
func TestThreeCopiesShareTheWork(t *testing.T) {
s, h := newMultiEdition(t)
var ids []int64
for i := 0; i < 6; i++ {
tm, _, _ := newTeam(t, s, "Team"+strconv.Itoa(i), "o"+strconv.Itoa(i)+"@x.example")
ids = append(ids, tm.ID)
}
copies := []*Server{s}
for i := 0; i < 2; i++ {
teams, err := s.platform().Teams()
if err != nil {
t.Fatal(err)
}
t.Cleanup(teams.Close)
c := &Server{DB: s.platform(), Platform: s.platform(), Teams: teams, Secrets: s.Secrets, Config: s.Config, DataDir: t.TempDir(),
PublicURL: s.PublicURL, Version: "test", Log: s.Log}
if _, err := c.Handler(); err != nil {
t.Fatal(err)
}
copies = append(copies, c)
}
var mu sync.Mutex
runs := map[int64]int{} // team → turns
byCopy := map[int]int{} // copy → turns it ran
var wg sync.WaitGroup
for i, c := range copies {
wg.Add(1)
go func() {
defer wg.Done()
c.jobDo(context.Background(), "scheduler", func(ctx context.Context, ts *Server) {
time.Sleep(150 * time.Millisecond) // a turn takes a while
mu.Lock()
runs[ts.team()]++
byCopy[i]++
mu.Unlock()
})
}()
}
wg.Wait()
for _, id := range ids {
if runs[id] != 1 {
t.Errorf("team %d ran %d times", id, runs[id])
}
}
shared := 0
for _, n := range byCopy {
if n > 0 {
shared++
}
}
if shared < 2 {
t.Errorf("one copy did it all: %v", byCopy)
}
// Any copy answers any request: a team's owner, signed in, on another
// copy.
_, _, c0 := newTeamOwnerCookie(t, s, ids[0])
h2, _ := copies[2].Handler()
if rec := as(h2, c0, http.MethodGet, "/settings/profile", nil); rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "Team0") {
t.Errorf("on another copy: %d", rec.Code)
}
_ = h
}