An owed act met by the forge away (401 while the store was replaced) ended could not be performed and nothing performed it again. Each act is now a kept call at the module's pace (kept-call-pace-first, kept-call-pace-max) until owed-away-bound (60 minutes), then ends could not be performed naming every try. Before each try the bridge reads the pull request through the seat git's pull: one closed unmerged ends owed.ended not-needed, never performed. The gate's owed event gains record (the delivery record's source revision), kept with the act in performed, and bridge_owed_again by record and why performs again every act of that record that ended could not be performed, written in the hand-act log first. Builds: design 47 H2 §807, §775, §819, H-A-432
62 lines
2.6 KiB
Go
62 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
|
|
"mesh-delivery-forge-bridge/internal/gitfixture"
|
|
)
|
|
|
|
// openerFake is a bus that opens no bucket and records each name asked.
|
|
type openerFake struct{ asked []string }
|
|
|
|
func (o *openerFake) KeyValue(_ context.Context, bucket string) (jetstream.KeyValue, error) {
|
|
o.asked = append(o.asked, bucket)
|
|
return nil, errors.New("no bucket in a unit test")
|
|
}
|
|
|
|
// performedIsOpenedByItsBinding: design 47 G §577, unit (forge bridge): the state performed is opened by the bus name
|
|
// the seat mesh-broker's show answers for its local name, never by an old name; until show answers no bucket is opened,
|
|
// the use names the entry, and nothing owed is performed.
|
|
func performedIsOpenedByItsBinding(t *testing.T) {
|
|
var shows []string
|
|
answered := false
|
|
show := func(key string, body any) (json.RawMessage, error) {
|
|
b, _ := json.Marshal(body)
|
|
shows = append(shows, key+" "+string(b))
|
|
if !answered {
|
|
return nil, errors.New("nats: no responders available for request")
|
|
}
|
|
return json.RawMessage(`{"state":"created","binding":{"local":"performed","storage":"key-value","bucket":"bound-performed"}}`), nil
|
|
}
|
|
binding := process.NewBinding(brokerSeat, forgeBridgeModule(), show, nil, performedLocal)
|
|
bus := &openerFake{}
|
|
kv := &boundBucket{binding: binding, local: performedLocal, js: bus}
|
|
binding.Ask(performedLocal)
|
|
if _, err := kv.Get(context.Background(), "k"); err == nil || !strings.Contains(err.Error(), `"performed"`) || len(bus.asked) != 0 {
|
|
t.Errorf("unbound: %v, opened %v; want an error naming the entry and no bucket opened", err, bus.asked)
|
|
}
|
|
f := &seatFake{}
|
|
o, pub, kept := newOwing(f)
|
|
o.waits = binding.Waiting
|
|
gate := gitfixture.Seat(t, seat.Seat, "events", "owed is said, a status", "event:owed")[0]
|
|
if _, err := o.heard(context.Background(), seat.Seat, gate, nil); err == nil || len(f.calls) != 0 || len(pub.data) != 0 || len(kept) != 0 {
|
|
t.Errorf("unbound: %v, called %v, said %d; want the act left unperformed and unsaid", err, f.calls, len(pub.data))
|
|
}
|
|
answered = true
|
|
binding.Ask(performedLocal)
|
|
_, _ = kv.Get(context.Background(), "k")
|
|
want := `seat:mesh-broker.show {"local-name":"performed","module":"mesh-delivery-forge-bridge"}`
|
|
if len(bus.asked) != 1 || bus.asked[0] != "bound-performed" || shows[len(shows)-1] != want {
|
|
t.Errorf("bound: opened %v after %v; want bound-performed, asked as %s", bus.asked, shows, want)
|
|
}
|
|
}
|