mesh-provisioner: a read of a followed state before its copy is read is the fault away
H-A-717's answer to DQ-55: the holder's handlers ask WatchedStates.Unread before they read the states it follows from its start; its own states, followed on first read, still wait. Builds: design 47 H2 H-A-708 (2), H-A-717 (DQ-55)
This commit is contained in:
@@ -1738,13 +1738,23 @@ func (w watchingStore) copied(state string) bool {
|
||||
return slices.Contains(WatchedReads, state) || slices.Contains(OwnStates, state)
|
||||
}
|
||||
|
||||
// unread is the fault `away` while the copy of a state the holder follows from its start is not read yet (design 47 H2
|
||||
// H-A-708 (2), H-A-717 DQ-55): a call made then is answered at once, never waits for the copy.
|
||||
func (w watchingStore) unread(state string) error {
|
||||
if !slices.Contains(WatchedReads, state) {
|
||||
return nil
|
||||
}
|
||||
return w.ws.Unread(state)
|
||||
}
|
||||
|
||||
func (w watchingStore) Get(state, key string) (*Entry, error) {
|
||||
get := w.ws.Get
|
||||
switch {
|
||||
case !w.copied(state):
|
||||
if !w.copied(state) {
|
||||
return w.Store.Get(state, key)
|
||||
}
|
||||
v, found, err := get(state, key)
|
||||
if err := w.unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, found, err := w.ws.Get(state, key)
|
||||
if err != nil || !found {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1755,6 +1765,9 @@ func (w watchingStore) Keys(state string) ([]string, error) {
|
||||
if !w.copied(state) {
|
||||
return w.Store.Keys(state)
|
||||
}
|
||||
if err := w.unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return w.ws.Keys(state)
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,10 @@ func TestTheHolderPlansProvidesAndAsksOnTheBus(t *testing.T) {
|
||||
return p
|
||||
}
|
||||
key := node + ".restic.postgres-database"
|
||||
// The holder follows its states from its start (main.go), so a read finds its copies read (H-A-708 (2)).
|
||||
for _, r := range WatchedReads {
|
||||
ws.Follow(r, nil)
|
||||
}
|
||||
if _, err := h.ComposeNode(ctx, node); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-contracts/provisioning/go/clients/meshprovisionerclient"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
@@ -486,6 +487,14 @@ func TestAModuleHeldWithoutAWantIsComposedAtTheBuildItRuns(t *testing.T) {
|
||||
}, func(string, string) ([]byte, bool, error) { return nil, false, nil })
|
||||
m.h.Store = Watching(bus, ws)
|
||||
wk := &work{pending: map[string]bool{}, wake: make(chan struct{}, 1)}
|
||||
// H-A-708 (2): a state the holder follows from its start, asked before its copy is read, is the fault `away` at once.
|
||||
var away *busretry.Away
|
||||
if _, err := m.h.Store.Keys(WantsRead); !errors.As(err, &away) || !strings.HasPrefix(away.Words, "not read yet since ") || len(watches) != 0 {
|
||||
t.Fatalf("a read before the copy: %v, watches %v", err, watches)
|
||||
}
|
||||
for _, r := range []string{AssignmentsRead, WantsRead} {
|
||||
ws.Follow(r, nil)
|
||||
}
|
||||
for _, r := range []string{ComposedRead, HaveRead} {
|
||||
ws.Follow(r, func(c stdio.StateChange) error { wk.add(NodesOfNodeKey(c.Key)...); return nil })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user