mesh-config: a read before its first view is answered is the fault away, naming the view
G21 config-first-view-away: views.Follower.Unread for the owners' views, WatchedStates.Unread for the module's own states, whose watches start with the module. Builds: design 47 H2 H-A-708 (2), H-A-717 (DQ-55 in part: mesh-config)
This commit is contained in:
@@ -149,6 +149,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
own.follow()
|
||||
c := &Config{Store: runtimeStore{own: own}, Logf: logf, Asks: runtimeAsks{},
|
||||
Delivery: toolDelivery{ask: stdio.Ask}, Vault: toolVault{ask: stdio.Ask, recorder: recorder}}
|
||||
// The module's one held writer (design 47 G §689, A-16, A-29, A-32): the renames' and retirements' findings and the views reader's go through it.
|
||||
|
||||
@@ -95,22 +95,15 @@ func (o *ownerViews) read(state string) (*views.Follower, bool) {
|
||||
return f, ok
|
||||
}
|
||||
|
||||
// errUnanswered says a first view is not answered yet: a reader waits, and its next resolution reads it.
|
||||
func errUnanswered(f *views.Follower) error {
|
||||
s := f.Status()
|
||||
return fmt.Errorf("the first view of %s's %s is not answered yet (%s asked %d times)", s.Owner, s.State, s.Tool, s.Asks)
|
||||
}
|
||||
|
||||
// get is one key of a followed state.
|
||||
func (o *ownerViews) get(state, key string) (*Entry, bool, error) {
|
||||
f, ok := o.read(state)
|
||||
if !ok {
|
||||
return nil, false, nil
|
||||
}
|
||||
select {
|
||||
case <-f.Ready():
|
||||
default:
|
||||
return nil, true, errUnanswered(f)
|
||||
// A first view not answered yet is the fault `away`, naming the view's owner verb (design 47 H2 H-A-708 (2)).
|
||||
if err := f.Unread(); err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
v, held := f.Get(key)
|
||||
if !held {
|
||||
@@ -125,10 +118,8 @@ func (o *ownerViews) keys(state string) ([]string, bool, error) {
|
||||
if !ok {
|
||||
return nil, false, nil
|
||||
}
|
||||
select {
|
||||
case <-f.Ready():
|
||||
default:
|
||||
return nil, true, errUnanswered(f)
|
||||
if err := f.Unread(); err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
var out []string
|
||||
for k := range f.Values() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
@@ -33,7 +34,10 @@ func TestAFollowedStateIsReadFromItsOwnersFirstViewAndEvents(t *testing.T) {
|
||||
}
|
||||
var changed atomic.Int32
|
||||
o := newOwnerViews(ask, func() { changed.Add(1) }, nopFindings{})
|
||||
if _, followed, err := o.get(WantsRead, "want.g14.dunst"); !followed || err == nil || !strings.Contains(err.Error(), "not answered yet") {
|
||||
// H-A-708 (2): a read before the first view is answered `away`, naming the view's owner verb, at once.
|
||||
var away *busretry.Away
|
||||
if _, followed, err := o.get(WantsRead, "want.g14.dunst"); !followed || !errors.As(err, &away) || away.Part != "mesh-delivery-assigner.assigner_read_wants" ||
|
||||
!strings.HasPrefix(away.Words, "not read yet since ") {
|
||||
t.Fatalf("before the first view: followed %v, %v", followed, err)
|
||||
}
|
||||
if !o.reader.Follows("mesh-delivery-assigner.wants") {
|
||||
|
||||
@@ -36,6 +36,10 @@ func newOwnCopy() *ownCopy {
|
||||
}
|
||||
|
||||
func (o *ownCopy) get(state, key string) (*Entry, error) {
|
||||
// A state whose copy is not read yet is the fault `away` at once, never a wait (design 47 H2 H-A-708 (2)).
|
||||
if err := o.copy.Unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw, ok, err := o.copy.Get(state, key)
|
||||
if err != nil || !ok {
|
||||
return nil, err
|
||||
@@ -43,7 +47,20 @@ func (o *ownCopy) get(state, key string) (*Entry, error) {
|
||||
return &Entry{Key: key, Value: raw}, nil
|
||||
}
|
||||
|
||||
func (o *ownCopy) keys(state string) ([]string, error) { return o.copy.Keys(state) }
|
||||
func (o *ownCopy) keys(state string) ([]string, error) {
|
||||
if err := o.copy.Unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return o.copy.Keys(state)
|
||||
}
|
||||
|
||||
// follow starts the watch of every state the copy holds, each on its goroutine, so a read asked before one is in is
|
||||
// answered `away` and the copy is read by the time it is asked again (Unread; design 47 H2 H-A-708 (2)).
|
||||
func (o *ownCopy) follow() {
|
||||
for state := range ownStates {
|
||||
go o.copy.Follow(state, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// write puts a key and takes it into the copy at the revision the bus answered.
|
||||
func (o *ownCopy) write(state, key string, value any) error {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
)
|
||||
|
||||
// countingStore counts the reads of the states by state: what the bus would be asked.
|
||||
@@ -203,6 +204,15 @@ func TestAnOwnStateIsReadFromItsWatchedCopyNotKeyByKey(t *testing.T) {
|
||||
}
|
||||
n := len(b.held[ValuesState])
|
||||
own := b.ownCopy()
|
||||
// H-A-708 (2): before the state's copy is read a read is the fault `away` at once, naming the state; the start's watch reads it.
|
||||
var away *busretry.Away
|
||||
if _, err := own.keys(ValuesState); !errors.As(err, &away) || away.Part != "the state "+ValuesState || !strings.HasPrefix(away.Words, "not read yet since ") {
|
||||
t.Fatalf("before the copy is read: %v", err)
|
||||
}
|
||||
if _, err := own.get(ValuesState, "mesh.key-0s"); !errors.As(err, &away) {
|
||||
t.Fatalf("a get before the copy is read: %v", err)
|
||||
}
|
||||
own.copy.Follow(ValuesState, nil)
|
||||
for pass := 0; pass < 3; pass++ {
|
||||
keys, err := own.keys(ValuesState)
|
||||
if err != nil || len(keys) != n {
|
||||
|
||||
Reference in New Issue
Block a user