S8 unread-away: Unread of a state and a view, the away answers, the start's phase
Builds: design 47 H2 H-A-708 (1) (2), H-A-717 (DQ-54, DQ-58)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -610,3 +611,35 @@ func strs(v any) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-708 (2): Unread says `away`, naming the state and since when, while the state's copy has not taken in its
|
||||
// current values, whether its watch is not asked for yet or is still handing them over, and nothing once it has.
|
||||
func TestAWatchedCopyIsUnreadUntilItsCurrentValuesAreIn(t *testing.T) {
|
||||
release, entered := make(chan struct{}), make(chan struct{})
|
||||
w := WatchedStatesOver(func(state string, handle func(StateChange) error) error {
|
||||
close(entered)
|
||||
<-release
|
||||
return handle(StateChange{State: state, Key: "a", Op: OpPut, Value: []byte("1"), Current: true})
|
||||
}, nil)
|
||||
asAway := func() *busretry.Away {
|
||||
var away *busretry.Away
|
||||
if !errors.As(w.Unread("placement"), &away) {
|
||||
return nil
|
||||
}
|
||||
return away
|
||||
}
|
||||
if a := asAway(); a == nil || a.Part != "the state placement" || !strings.HasPrefix(a.Words, "not read yet since ") {
|
||||
t.Fatalf("before the watch is asked: %+v", a)
|
||||
}
|
||||
done := make(chan struct{})
|
||||
go func() { _, _ = w.Keys("placement"); close(done) }()
|
||||
<-entered
|
||||
if a := asAway(); a == nil {
|
||||
t.Fatal("while the watch hands its current values over, the copy is read")
|
||||
}
|
||||
close(release)
|
||||
<-done
|
||||
if err := w.Unread("placement"); err != nil {
|
||||
t.Fatalf("after the current values are in: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user