mesh-sdk holds neither asks nor asker, nor the vault's answer types, and mesh-delivery's sdk/views is mesh-sdk's go/views (a1-progress.md, the rewrite map for the join): thirteen modules switch to the operatorchannel contract and client, mesh-sdk's channel package and meshvault, with go.mod requiring each at the group pin (nats: meshbroker too). The gate holds the checks mesh-sdk dropped (an ask's id is its key's asking, at least one option), with a row that fails without them; claude-code refuses a router record whose times do not parse, as its JSON decode did, with a row. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/views"
|
|
)
|
|
|
|
// ADR 0615 §6: the vault started while the assigner is down keeps asking, never reads its bucket, and past the bound
|
|
// writes a finding naming the owner and the tool for the condition keeper; the answer deletes it. Before the answer a read
|
|
// of the placement is an error.
|
|
func TestAnUnansweredFirstViewOfThePlacementIsAFindingTheAnswerClears(t *testing.T) {
|
|
var mu sync.Mutex
|
|
up := false
|
|
held := map[string]json.RawMessage{}
|
|
ask := func(string, any) (json.RawMessage, error) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if !up {
|
|
return nil, errors.New("nats: no responders available for request")
|
|
}
|
|
raw, _ := json.Marshal(views.Answer{V: 1, Owner: "mesh-delivery-assigner", State: "placement", Revision: 1, Created: time.Now(),
|
|
Values: map[string]json.RawMessage{"g14.node": json.RawMessage(`{}`)}})
|
|
return raw, nil
|
|
}
|
|
put := func(k string, v json.RawMessage) error { mu.Lock(); held[k] = v; mu.Unlock(); return nil }
|
|
drop := func(k string) error { mu.Lock(); delete(held, k); mu.Unlock(); return nil }
|
|
f := newPlacementView(ask, func(string) {}, put, drop)
|
|
f.Bound, f.Wait = 30*time.Millisecond, 10*time.Millisecond
|
|
reader := viewPlacement(func() *views.Follower { return f })
|
|
if _, err := reader.Keys(); err == nil {
|
|
t.Fatal("the placement was read before its first view")
|
|
}
|
|
done := make(chan error, 1)
|
|
go func() { done <- f.Start(context.Background()) }()
|
|
count := func() int { mu.Lock(); defer mu.Unlock(); return len(held) }
|
|
for end := time.Now().Add(5 * time.Second); count() == 0 && time.Now().Before(end); time.Sleep(10 * time.Millisecond) {
|
|
}
|
|
if count() != 1 {
|
|
t.Fatalf("past its bound the vault wrote %d findings, want one", count())
|
|
}
|
|
mu.Lock()
|
|
up = true
|
|
mu.Unlock()
|
|
if err := <-done; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count() != 0 {
|
|
t.Errorf("the answer left %d findings", count())
|
|
}
|
|
if keys, err := reader.Keys(); err != nil || len(keys) != 1 || keys[0] != "g14.node" {
|
|
t.Errorf("keys %v, %v", keys, err)
|
|
}
|
|
}
|