The review found two faults. The tool paged on through a state of any size, one replay of the bucket per page; it now reads one page of each of its own states and, when the state holds more, answers that page capped, with the keys read and the state's size from its info, never asking a second page and never refusing. And the retiring of superseded done builds keyed the newest reservation and release by module alone, so a standing 0.2 would retire a done 0.1.x; both are now found per module and series (MAJOR.MINOR). Builds: design 47 H H-A-292, H-A-293, H-A-291 (1), H-A-290 (5)
45 lines
1.9 KiB
Go
45 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// TestAStateIsReadInOnePage: design 47 H H-A-292, H-A-293 — builder_publish_queue reads each of its own states in one page and
|
|
// never asks a second: a state past the page answers that page with More and the state's size from its info; one the page holds
|
|
// answers whole without reading the info.
|
|
func TestAStateIsReadInOnePage(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name string
|
|
next string
|
|
}{{"past one page", "k1"}, {"held by one page", ""}} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var asked []string
|
|
infos := 0
|
|
page := func(after string, maxBytes int, budget time.Duration) (stdio.StatePage, error) {
|
|
asked = append(asked, after)
|
|
if after != "" {
|
|
return stdio.StatePage{Entries: []stdio.StateEntry{{Key: "k2", Value: json.RawMessage(`2`)}}}, nil
|
|
}
|
|
return stdio.StatePage{Entries: []stdio.StateEntry{{Key: "k1", Value: json.RawMessage(`1`)}}, Next: c.next}, nil
|
|
}
|
|
info := func() (*stdio.StateInfo, error) { infos++; return &stdio.StateInfo{Keys: 2, Bytes: 640}, nil }
|
|
pg, err := onePage(page, info)
|
|
more := c.next != ""
|
|
if err != nil || len(asked) != 1 || len(pg.Values) != 1 || pg.More != more || (more && (pg.Keys != 2 || pg.Bytes != 640 || infos != 1)) || (!more && infos != 0) {
|
|
t.Errorf("asked the pages after %q, read %v, more %v, size %d keys %d bytes, info read %d times (%v): want one page only, its rest said with the state's size", asked, pg.Values, pg.More, pg.Keys, pg.Bytes, infos, err)
|
|
}
|
|
})
|
|
}
|
|
unsupported := func(string, int, time.Duration) (stdio.StatePage, error) {
|
|
return stdio.StatePage{}, errors.ErrUnsupported
|
|
}
|
|
if _, err := onePage(unsupported, nil); !errors.Is(err, errors.ErrUnsupported) {
|
|
t.Errorf("a runtime with no pages answered %v, want ErrUnsupported so the reader reads key by key", err)
|
|
}
|
|
}
|