A check ask handed out five times during a bus reload was given up into DEAD_LETTERS and no build node wrote a step for it, so try-1793017340003993788 stayed running for ever, held one of the four try places, and checker_try of its head kept answering its id. The checker now hears the copies DEAD_LETTERS keeps of the build seats' given-up asks (an ordered consumer from its start; the grant is mesh-sdk/mesh-controller DeadLetterReads, branch fix/734-lost-ask) and ends the step it waits for: a try ends as error saying why, a check is asked again under its claim, up to three times, then fails as not heard. A try whose ask no node takes within the step bound ends the same way (a check's backlog stays no fault, ADR 0525 §9). checker_try_end ends a try by hand, freeing its place and stopping its judging.
96 lines
3.3 KiB
Go
96 lines
3.3 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)
|
|
}
|
|
// 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)
|
|
}
|
|
}
|