Design 47 H2's corrections: movers carried beside a failed one, validate, acted lifetimes, publish asked again (issue 1984) #365
@@ -168,6 +168,32 @@ func TestWhatIsOwedIsPerformedSaidAndKept(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-712 (3), DQ-48: an act performed that is heard again says its kept outcome once more as owed.ended, its `at` the
|
||||
// time it was performed, calls the seat git not at all and writes performed not again.
|
||||
t.Run("an act performed, heard again", func(t *testing.T) {
|
||||
f := &seatFake{answers: statusOK}
|
||||
o, pub, kept := newOwing(f)
|
||||
first, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status"), nil)
|
||||
if err != nil || first.Outcome != forgemsg.OwedPerformed || len(f.calls) != 1 || len(pub.data) != 1 {
|
||||
t.Fatalf("the first hearing: %+v %v, called %v, said %d", first, err, f.calls, len(pub.data))
|
||||
}
|
||||
performedAt, key := first.At, performedKey(seat.Seat, first.ID)
|
||||
stored := string(kept[key])
|
||||
later := performedAt.Add(time.Hour)
|
||||
o.now = func() time.Time { return later }
|
||||
again, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status"), nil)
|
||||
if err != nil || again.Outcome != forgemsg.OwedPerformed || len(f.calls) != 1 || len(pub.data) != 2 {
|
||||
t.Fatalf("heard again: %+v %v, called %v, said %d; want its outcome said once more and the seat git not called", again, err, f.calls, len(pub.data))
|
||||
}
|
||||
e, err := forgemsg.DecodeOwedEnded(pub.data[1])
|
||||
if err != nil || e.ID != first.ID || e.Outcome != forgemsg.OwedPerformed || !e.At.Equal(performedAt) {
|
||||
t.Errorf("said again as %+v %v, want the outcome kept, at %s", e, err, performedAt)
|
||||
}
|
||||
if string(kept[key]) != stored {
|
||||
t.Errorf("performed was written again: %s, was %s", kept[key], stored)
|
||||
}
|
||||
})
|
||||
|
||||
// Design 47 H2 §807, §775: an act met by the seat git's away is called again at the kept-call pace, its pull request
|
||||
// read before each try, and performed when the forge answers; one away past owed-away-bound ends could not be
|
||||
// performed, naming every try.
|
||||
@@ -224,8 +250,8 @@ func TestWhatIsOwedIsPerformedSaidAndKept(t *testing.T) {
|
||||
o.hear(context.Background(), seat.Seat, m)
|
||||
again := &fakeMsg{subject: m.subject, data: m.data}
|
||||
o.hear(context.Background(), seat.Seat, again)
|
||||
if m.acked != 1 || again.acked != 1 || len(f.calls) != 1 || len(pub.data) != 1 {
|
||||
t.Errorf("an act said twice: acked %d and %d, called %v, said %d; want performed and said once, both acknowledged",
|
||||
if m.acked != 1 || again.acked != 1 || len(f.calls) != 1 || len(pub.data) != 2 {
|
||||
t.Errorf("an act said twice: acked %d and %d, called %v, said %d; want performed once, its outcome said twice (H-A-712 (3)), both acknowledged",
|
||||
m.acked, again.acked, f.calls, len(pub.data))
|
||||
}
|
||||
pub.err = errors.New("no responders")
|
||||
|
||||
@@ -601,6 +601,10 @@ func TestBridgePerformsWhatIsOwedOnce(t *testing.T) {
|
||||
if e := ended(); e.Outcome != forgemsg.OwedPerformed || e.Of != seat.Seat {
|
||||
t.Errorf("the gate's status: %+v, want performed", e)
|
||||
}
|
||||
// H-A-712 (3), DMC-17: the act said twice is performed once, and its kept outcome is said once more, before the undecodable one.
|
||||
if e := ended(); e.Outcome != forgemsg.OwedPerformed || e.Of != seat.Seat {
|
||||
t.Errorf("the gate's status said again: %+v, want its performed outcome once more", e)
|
||||
}
|
||||
if _, err := b.js.Publish(b.ctx, subject, []byte("{")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -105,7 +105,12 @@ func (o *owing) heard(ctx context.Context, of string, data []byte, tried func())
|
||||
return forgemsg.OwedEnded{Of: c.Of, ID: c.ID}, fmt.Errorf("the bridge %s", w)
|
||||
}
|
||||
if o.held(ctx, c.Of, c.ID) {
|
||||
// said twice, or said again while its outcome was on its way: performed once, the outcome said once
|
||||
// Said twice, or said again at the gate's start: performed once, nothing done at the forge, and the outcome kept
|
||||
// here said once more as owed.ended, so the gate ends an act it still holds (design 47 H2 H-A-712 (3), DQ-48). Its
|
||||
// `at` is the time it was performed, and performed is not written again.
|
||||
if p, err := o.kept(ctx, c.Of, c.ID); err == nil && p.Ended.ID == c.ID {
|
||||
return p.Ended, o.say(ctx, p.Ended)
|
||||
}
|
||||
return forgemsg.OwedEnded{Of: c.Of, ID: c.ID}, nil
|
||||
}
|
||||
return o.perform(ctx, c, tried)
|
||||
@@ -202,12 +207,8 @@ func (o *owing) closed(ctx context.Context, c bridge.OwedCall) (string, error) {
|
||||
// which changes nothing at the forge.
|
||||
func (o *owing) end(ctx context.Context, e forgemsg.OwedEnded, c bridge.OwedCall) (forgemsg.OwedEnded, error) {
|
||||
e.At = o.now().UTC()
|
||||
data, err := forgemsg.EncodeOwedEnded(e)
|
||||
if err != nil {
|
||||
return e, fmt.Errorf("the outcome of the owed %s cannot be said: %w", e.ID, err)
|
||||
}
|
||||
if _, err := o.pub.Publish(ctx, forgeSubject(forgemsg.OwedEndedEvent), data); err != nil {
|
||||
return e, fmt.Errorf("the outcome %s of the owed %s could not be said on the stream forge: %w", e.Outcome, e.ID, err)
|
||||
if err := o.say(ctx, e); err != nil {
|
||||
return e, err
|
||||
}
|
||||
if e.ID == "" {
|
||||
return e, nil // an undecodable act with no id is said, and has no key to keep
|
||||
@@ -222,6 +223,18 @@ func (o *owing) end(ctx context.Context, e forgemsg.OwedEnded, c bridge.OwedCall
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// say publishes an act's outcome as owed.ended on the stream forge, as it stands (its `at` untouched).
|
||||
func (o *owing) say(ctx context.Context, e forgemsg.OwedEnded) error {
|
||||
data, err := forgemsg.EncodeOwedEnded(e)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the outcome of the owed %s cannot be said: %w", e.ID, err)
|
||||
}
|
||||
if _, err := o.pub.Publish(ctx, forgeSubject(forgemsg.OwedEndedEvent), data); err != nil {
|
||||
return fmt.Errorf("the outcome %s of the owed %s could not be said on the stream forge: %w", e.Outcome, e.ID, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// held says whether performed holds an outcome of the act already. One that cannot be read is not held: the act is
|
||||
// performed again, which changes nothing at the forge.
|
||||
func (o *owing) held(ctx context.Context, of, id string) bool {
|
||||
|
||||
Reference in New Issue
Block a user