assigner: assigner_inputs says when the key-gone objects cannot be listed; the start's drop is asserted (A-465)
Builds: design 47 G-22 A-465
This commit is contained in:
@@ -407,15 +407,21 @@ func inputsRead(k *inputKeeper) stdio.Tool {
|
||||
}
|
||||
gone := []map[string]any{}
|
||||
var goneBytes int64
|
||||
if kept, err := k.vals.Kept(); err == nil {
|
||||
for _, o := range kept {
|
||||
if o.KeyGone {
|
||||
gone = append(gone, map[string]any{"object": o.Name, "key": o.Key, "size": o.Size})
|
||||
goneBytes += o.Size
|
||||
}
|
||||
answer := map[string]any{"inputs": out}
|
||||
kept, err := k.vals.Kept()
|
||||
if err != nil {
|
||||
// never an empty list for objects that could not be read (A-465)
|
||||
answer["key-gone-error"] = fmt.Sprintf("the objects of the state inputs cannot be listed, so key-gone objects are not known: %v", err)
|
||||
return answer, nil
|
||||
}
|
||||
for _, o := range kept {
|
||||
if o.KeyGone {
|
||||
gone = append(gone, map[string]any{"object": o.Name, "key": o.Key, "size": o.Size})
|
||||
goneBytes += o.Size
|
||||
}
|
||||
}
|
||||
return map[string]any{"inputs": out, "key-gone": gone, "key-gone-bytes": goneBytes}, nil
|
||||
answer["key-gone"], answer["key-gone-bytes"] = gone, goneBytes
|
||||
return answer, nil
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -71,8 +72,9 @@ func (k *kvMem) Keys() ([]string, error) {
|
||||
}
|
||||
|
||||
type objectsMem struct {
|
||||
mu sync.Mutex
|
||||
objs map[string][]byte
|
||||
mu sync.Mutex
|
||||
objs map[string][]byte
|
||||
listErr error // List fails with it
|
||||
}
|
||||
|
||||
func (*objectsMem) MostBytes() int { return 0 }
|
||||
@@ -100,6 +102,9 @@ func (o *objectsMem) Delete(name string) error {
|
||||
func (o *objectsMem) List() ([]stateobjects.Object, error) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
if o.listErr != nil {
|
||||
return nil, o.listErr
|
||||
}
|
||||
var out []stateobjects.Object
|
||||
for n, d := range o.objs {
|
||||
out = append(out, stateobjects.Object{Name: n, Size: int64(len(d))})
|
||||
@@ -297,5 +302,47 @@ func TestAnEndedInputEndsItsObjectAndTheDropToolRemovesWhatAKeyLeft(t *testing.T
|
||||
if err != nil || out.(map[string]any)["count"] != 1 || len(objs.objs) != 1 {
|
||||
t.Fatalf("assigner_inputs_drop = %+v %v, %d objects left: want one removed and the live one kept", out, err, len(objs.objs))
|
||||
}
|
||||
// The start drops what a key left, said with its count and bytes.
|
||||
if _, err := k.keep("ask-five", live); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, key := range keysOf(t, k) {
|
||||
if !strings.HasPrefix(key, inputsAskPrefix) {
|
||||
_ = k.vals.KV.Delete(key)
|
||||
}
|
||||
}
|
||||
var logged []string
|
||||
k.logf = func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }
|
||||
before := len(objs.objs)
|
||||
k.dropAtStart()
|
||||
if len(objs.objs) != 0 || before == 0 || len(logged) != 1 || !strings.Contains(logged[0], fmt.Sprintf("%d objects of deleted keys removed at the start", before)) || !strings.Contains(logged[0], " bytes") {
|
||||
t.Errorf("the start left %d of %d objects and said %q: want every key-gone object removed and its count and bytes said", len(objs.objs), before, logged)
|
||||
}
|
||||
}
|
||||
|
||||
func keysOf(t *testing.T, k *inputKeeper) []string {
|
||||
t.Helper()
|
||||
keys, err := k.vals.KV.Keys()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// Design 47 G A-465: assigner_inputs says why key-gone objects are not known when the objects cannot be listed, and never
|
||||
// answers them as none.
|
||||
func TestAssignerInputsSaysWhenTheKeyGoneObjectsCannotBeListed(t *testing.T) {
|
||||
objs := &objectsMem{objs: map[string][]byte{}, listErr: errors.New("the object store does not answer")}
|
||||
k := testKeeper(objs, time.Now)
|
||||
out, err := inputsRead(k).Run(map[string]any{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := out.(map[string]any)
|
||||
if msg, _ := m["key-gone-error"].(string); !strings.Contains(msg, "does not answer") {
|
||||
t.Errorf("answer %+v: want key-gone-error naming the failure", m)
|
||||
}
|
||||
if _, has := m["key-gone"]; has {
|
||||
t.Errorf("answer %+v: an unreadable store is not answered as no key-gone objects", m)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user