A start's first dsh round read every profile through the yaml emitter to
find what the last magpie's round had found: nothing to write. On a real
account that was ~60 MB of the first minute's 523 MB.
The round's key (dsh's files, the gateway, the models) is now summed with
sha256, the same in every process, and a round that ends with nothing to
write records it in the cache folder (dsh-rounds.json, temp + rename).
A start's first round goes by that record when it is this magpie
version's; a dev build never does. A file, the models or the version
changed has the round run as before.
Run:
- go test ./internal/agent (mica): ok 188s.
- GOOS=darwin/linux/windows go vet ./internal/agent ./internal/gateway
./internal/appdir: ok.
- Broken by hand: with the record not read, TestDshFirstRoundGoesByTheLastMagpies
is red ("read and wrote dsh's files 1 times").
- Real account, mote sandbox HOME, a start after one start (pprof
alloc_space at 50s): dshRounds.once 101 MB -> 38 MB (the catalog
only), yaml emitter 43 MB -> none, total 522 MB -> 463 MB. Footprint
peak 168 MB (w11) -> 165 MB.
Not tried: Windows and Linux real starts; the record is plain JSON in
appdir.Cache() there too.
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// A start's first dsh round read every profile through the yaml emitter,
|
|
// ~43 MB of a real account's first minute, to find what the last magpie's
|
|
// round had found: nothing to write (#2278). It goes by the last one's
|
|
// record now, and does the round when a file, the models or magpie's
|
|
// version is not what that record went by.
|
|
func TestDshFirstRoundGoesByTheLastMagpies(t *testing.T) {
|
|
was := gateway.Version
|
|
t.Cleanup(func() { gateway.Version = was })
|
|
gateway.Version = "0.1.9999-test"
|
|
_, web := dshSettled(t)
|
|
|
|
start := func() *dshRounds {
|
|
t.Helper()
|
|
r := &dshRounds{}
|
|
r.once()
|
|
if !r.done {
|
|
t.Fatal("a start's round with nothing to write is not kept")
|
|
}
|
|
return r
|
|
}
|
|
worked := func(f func()) int64 {
|
|
n := dshRoundsWorked.Load()
|
|
f()
|
|
return dshRoundsWorked.Load() - n
|
|
}
|
|
if n := worked(func() { start() }); n != 0 {
|
|
t.Fatalf("a start with nothing changed since the last magpie read and wrote dsh's files %d times", n)
|
|
}
|
|
|
|
b, _ := os.ReadFile(web)
|
|
if err := os.WriteFile(web, append(b, "# the user's\n"...), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n := worked(func() { start() }); n != 1 {
|
|
t.Fatalf("a start after the patch list changed did %d rounds, want 1", n)
|
|
}
|
|
if n := worked(func() { start() }); n != 0 {
|
|
t.Fatalf("the round after a change is not what the next start goes by (%d rounds)", n)
|
|
}
|
|
|
|
gateway.Version = "0.1.10000-test"
|
|
if n := worked(func() { start() }); n != 1 {
|
|
t.Fatalf("another magpie version went by this one's record (%d rounds)", n)
|
|
}
|
|
gateway.Version = "dev"
|
|
if n := worked(func() { start() }); n != 1 {
|
|
t.Fatalf("a dev build went by a record (%d rounds)", n)
|
|
}
|
|
}
|