S7 safe for concurrent use: hold the bus wrappers to it under the race detector

Many goroutines' gets, puts, pages, keys and watches through one bundle's
runtime channel, one process connection's state and one process reader's
pictures run under the race detector; no unguarded call was found, so the
tests hold the wrappers to it.

Builds: design 47 H2 §782; H-A-349 DQ-3
This commit is contained in:
2026-11-22 00:03:19 +01:00
parent e9481928f5
commit eee02a20a9
3 changed files with 174 additions and 0 deletions
+47
View File
@@ -1488,3 +1488,50 @@ func TestFirstViewsSayTheOwnBuild(t *testing.T) {
t.Errorf("nothing kept: %v", read)
}
}
// Design 47 H2 §782: one process reader's pictures are safe at once: gets, keys and watches from many goroutines while
// the owner's events change the picture and further views are followed, under the race detector.
func TestOneProcessReaderServesConcurrentReads(t *testing.T) {
made := time.Date(2026, 11, 22, 0, 0, 0, 0, time.UTC)
r := &ProcessReader{Module: "reader", Call: func(string, any) (json.RawMessage, error) {
return json.Marshal(Answer{V: Version, Owner: "o", State: "s", Revision: 1, Created: made, Values: map[string]json.RawMessage{"a": json.RawMessage(`1`)}})
}}
p, err := r.Follow("o", "s", "o.o_read")
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := p.Follower().Start(ctx); err != nil {
t.Fatal(err)
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := range 200 {
p.Follower().Apply(Event{V: Version, Owner: "o", State: "s", Key: fmt.Sprintf("k%d", i%7), Revision: uint64(i + 2), Created: made, Value: json.RawMessage(`2`)})
}
}()
for i := range 16 {
wg.Add(1)
go func() {
defer wg.Done()
w, err := p.Watch(ctx, ">")
if err != nil {
t.Error(err)
return
}
defer w.Stop()
for range 20 {
_, _ = p.Get(ctx, "a")
_, _ = p.Keys(ctx)
_ = r.Followers()
}
if _, err := r.Follow("o", fmt.Sprintf("s%d", i), "o.o_read"); err != nil {
t.Error(err)
}
}()
}
wg.Wait()
}