The providers' page asked MemberGroups for each provider and GroupKept
for each model, and each call built the groups again from every
provider's entries: 11.6 MB of what twenty window polls allocated with
real accounts (m2463 profile). Both now go through heldFrom, as the
other catalog reads do: built once per Hold, kept across requests
while the stamp stays, shared and only for reading.
Test: TestMemberGroupsBuiltOnceWhileHeld. 20 looks under one Hold,
each asking MemberGroups 12 times, build it once at most; a group
saved after (g5) is in the next look.
Run on mote, at this tree on dd7442f28:
- gofmt, go vet (darwin, windows, linux): ok
- the new test with TestUnlistedGroupKept, 3 times: ok
- broken by hand (MemberGroups built afresh each call): red, "20
looks under one Hold built the member groups 20 times, want 1 at
most"
- go test ./internal/provider: ok. TestModelSpecWinsOverTheListAndASync
was red once in the run before (with only the test's assertion
since fixed) and ok alone 3 times and in this run: #4637
- go test ./internal/gui: every test ok except the known
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949)
Not run: an A/B with the real-account sandbox for this change alone.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// The providers' page asked MemberGroups once for each provider, and each
|
|
// built the groups' members over the whole catalog again: 11.6 MB of
|
|
// what twenty polls allocated. While a request holds the catalog it is
|
|
// built once, and a group saved is in the next request's.
|
|
func TestMemberGroupsBuiltOnceWhileHeld(t *testing.T) {
|
|
groupHeldFixture(t)
|
|
look := func() map[string][]string {
|
|
defer Hold()()
|
|
var in map[string][]string
|
|
for range 12 {
|
|
in = MemberGroups()
|
|
}
|
|
return in
|
|
}
|
|
look()
|
|
before := memberGroupsBuilt.Load()
|
|
release := Hold()
|
|
for range 20 {
|
|
if gs := MemberGroups()["p2/m1"]; !slices.Contains(gs, GroupPrefix+"g4") {
|
|
t.Fatalf("p2/m1 is in %q, not group/g4", gs)
|
|
}
|
|
}
|
|
release()
|
|
if n := memberGroupsBuilt.Load() - before; n > 1 {
|
|
t.Fatalf("20 looks under one Hold built the member groups %d times, want 1 at most", n)
|
|
}
|
|
if err := SaveGroup(Group{ID: "g5", Name: "G5", Members: []string{"p5/m5"}, Routing: Ordered}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if gs := look()["p5/m5"]; !slices.Contains(gs, GroupPrefix+"g5") {
|
|
t.Fatalf("a group saved: p5/m5 is in %q, not group/g5", gs)
|
|
}
|
|
}
|