mesh-catalog #553's verdict stayed running after its step mvsgthyjed5786 passed on shanks at 19:09:31Z: the watch of that one step key, opened at 18:46:05Z, heard neither its start nor its end and never closed, so the wait had no bound running and nothing would ever judge it. - HeardEnds stands between the asker and each ask's watch: at every step end of the same build module (one watch per steps state), at a reconnect, the asks waited on read their keys now and are judged; a watch that closes is opened again, at most 3 times. - A step the build module's next process ended (RestartReason, a delivery replacing it) counts as a lost ask: asked again under the claim, at most LostAskTries, then failed as not heard, judged again when the nodes change. - checker_ask_again {group, why} ends a running verdict as asked again by hand; the checker hears its verdicts, ends the wait and claims it anew. Refused while a step of its pull requests runs, or for a verdict that is not running. - checker_status names such checks under lost, and each step's what. Tests: one table replaces the given-up test (rows for given up, replaced, deaf and nudged, deaf and asked by hand); counts unchanged (147 unit, 10 integration in the checker).
104 lines
3.7 KiB
Go
104 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"mesh-delivery-checker/internal/check"
|
|
)
|
|
|
|
func TestTheToolsServedAreTheFiveReadTools(t *testing.T) {
|
|
var names []string
|
|
for _, tl := range Tools(check.Reader{}) {
|
|
names = append(names, tl.Name)
|
|
if tl.Description == "" || tl.Run == nil {
|
|
t.Errorf("%s has no description or no run", tl.Name)
|
|
}
|
|
}
|
|
want := []string{check.VerdictsReadTool, check.PullReadTool, check.KeptReadTool, check.PreviewsReadTool, check.StatusReadTool}
|
|
if !slices.Equal(names, want) {
|
|
t.Errorf("tools = %v, want %v", names, want)
|
|
}
|
|
// The recovery tool beside them asks a lost check again; with nothing to write it refuses.
|
|
recovery := RecoveryTools(check.Reader{}, nil)
|
|
if len(recovery) != 1 || recovery[0].Name != check.AskAgainTool || recovery[0].Description == "" {
|
|
t.Errorf("recovery tools = %+v", recovery)
|
|
}
|
|
if _, err := recovery[0].Run(map[string]any{"group": "feat/x", "why": "lost"}); err == nil {
|
|
t.Errorf("%s answered with no state to write", check.AskAgainTool)
|
|
}
|
|
// With nothing to read from a tool says so and changes nothing.
|
|
for _, tl := range Tools(check.Reader{}) {
|
|
if tl.Name == check.StatusReadTool {
|
|
continue // it answers from what it can read, and says what it could not
|
|
}
|
|
if _, err := tl.Run(map[string]any{"repository": "novox/x", "number": float64(1)}); err == nil {
|
|
t.Errorf("%s answered with no state to read", tl.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// memStore is a tries state in memory.
|
|
type memStore struct{ vals map[string]json.RawMessage }
|
|
|
|
func (m *memStore) Keys() ([]string, error) {
|
|
var out []string
|
|
for k := range m.vals {
|
|
out = append(out, k)
|
|
}
|
|
return out, nil
|
|
}
|
|
func (m *memStore) Get(key string) (json.RawMessage, error) { return m.vals[key], nil }
|
|
func (m *memStore) Create(key string, value []byte) error {
|
|
if _, ok := m.vals[key]; ok {
|
|
return errors.New("exists")
|
|
}
|
|
m.vals[key] = value
|
|
return nil
|
|
}
|
|
|
|
func (m *memStore) Entry(key string) (json.RawMessage, uint64, error) { return m.vals[key], 1, nil }
|
|
func (m *memStore) Update(key string, value []byte, revision uint64) error {
|
|
m.vals[key] = value
|
|
return nil
|
|
}
|
|
|
|
func TestTheTryToolsAskAndReadATry(t *testing.T) { // ADR 0501 §5, the agreed interface with mesh-controller's try
|
|
store := &memStore{vals: map[string]json.RawMessage{}}
|
|
tools := TryTools(Trying{Tries: store, Ender: store, Now: func() time.Time { return time.Unix(1, 5) },
|
|
Trunks: func() (map[string]string, error) {
|
|
return map[string]string{"novox/mesh-delivery": strings.Repeat("a", 40)}, nil
|
|
}})
|
|
if len(tools) != 3 || tools[0].Name != "checker_try" || tools[1].Name != "checker_try_read" || tools[2].Name != "checker_try_end" {
|
|
t.Fatalf("tools = %+v", tools)
|
|
}
|
|
out, err := tools[0].Run(map[string]any{"repository": "novox/mesh-delivery", "head": strings.Repeat("1", 40), "trunk": "main"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id := out.(map[string]any)["id"].(string)
|
|
if id != "try-1000000005" {
|
|
t.Errorf("id = %q", id)
|
|
}
|
|
raw, err := tools[1].Run(map[string]any{"id": id})
|
|
if err != nil || !strings.Contains(string(raw.(json.RawMessage)), `"state":"queued"`) {
|
|
t.Errorf("read = %s, %v", raw, err)
|
|
}
|
|
// Issue 734: a try whose ask was lost is ended by hand with why, and its head is asked anew.
|
|
ended, err := tools[2].Run(map[string]any{"id": id, "why": "its ask was lost"})
|
|
if err != nil || ended.(map[string]any)["state"] != "error" {
|
|
t.Errorf("end = %v, %v", ended, err)
|
|
}
|
|
if _, err := tools[2].Run(map[string]any{"id": id, "why": "again"}); err == nil {
|
|
t.Error("an ended try was ended again")
|
|
}
|
|
if _, err := tools[0].Run(map[string]any{"repository": "novox/hq", "head": strings.Repeat("1", 40)}); err == nil ||
|
|
err.Error() != "no level of novox/hq is checked by the checker" {
|
|
t.Errorf("hq: %v", err)
|
|
}
|
|
}
|