Design 47 H1 (3): a publish whose recompute fails is not acknowledged
The registry's published is offered again when the recompute of its users fails, as a failed series write already was. Builds: design 47 H S15 (H-pins-spec-and-gaps item 3), H-A-167
This commit is contained in:
@@ -22,8 +22,8 @@ var (
|
||||
)
|
||||
|
||||
// heardVersion reads one message of the consumer as a version, false for any other subject. A package's is kept in its
|
||||
// series; one that does not decode is said and acknowledged; a write that fails is left unacknowledged, so the bus gives
|
||||
// it again.
|
||||
// series; one that does not decode is said and acknowledged; a write that fails, or the recompute of its users that a
|
||||
// publish starts, is left unacknowledged, so the bus gives it again.
|
||||
func heardVersion(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) bool {
|
||||
var h index.HeardVersion
|
||||
switch seat, ok := publishedSeats[m.Subject()]; {
|
||||
@@ -53,8 +53,10 @@ func heardVersion(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf
|
||||
}
|
||||
if kept && h.Published {
|
||||
// A series' newest moved: its users' fingerprints take it (DLV-I6), in the same turn as the publish is heard.
|
||||
// A recompute that fails is not acknowledged, so the publish is offered again (design 47 H S15, H-A-167).
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
logf("writing the modules again after %s %s was published: %v", h.Package, h.Version, err)
|
||||
logf("writing the modules again after %s %s was published failed, so the bus gives it again: %v", h.Package, h.Version, err)
|
||||
return true
|
||||
}
|
||||
}
|
||||
_ = m.Ack()
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// ackedMsg is a message that counts its acknowledgements.
|
||||
type ackedMsg struct {
|
||||
jetstream.Msg
|
||||
subject string
|
||||
data []byte
|
||||
acked int
|
||||
}
|
||||
|
||||
func (a *ackedMsg) Subject() string { return a.subject }
|
||||
func (a *ackedMsg) Data() []byte { return a.data }
|
||||
func (a *ackedMsg) Ack() error { a.acked++; return nil }
|
||||
|
||||
// unlistedStore is a store whose listing fails: a recompute over it fails.
|
||||
type unlistedStore struct{ memStore }
|
||||
|
||||
func (unlistedStore) Keys(context.Context) ([]string, error) {
|
||||
return nil, errors.New("the bus does not answer")
|
||||
}
|
||||
|
||||
// TestHeardVersionRecomputeFailed: a publish whose recompute of its users fails is not acknowledged, so the bus gives
|
||||
// it again (design 47 H S15, the pin specification's item 3); one whose recompute passes is.
|
||||
func TestHeardVersionRecomputeFailed(t *testing.T) {
|
||||
data, err := json.Marshal(gopackageregistry.PublishedEvent{Kind: "package", Name: "git.example/novox/lib", Version: "0.1.4"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
modules index.Store
|
||||
acked int
|
||||
}{
|
||||
{"recompute fails", &unlistedStore{memStore{vals: map[string][]byte{}}}, 0},
|
||||
{"recompute passes", &memStore{vals: map[string][]byte{}}, 1},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
ix := &index.Indexer{Packages: &memStore{vals: map[string][]byte{}}, Modules: c.modules, Manifests: &memStore{vals: map[string][]byte{}}}
|
||||
m := &ackedMsg{subject: gopackageregistry.SubjectPublished, data: data}
|
||||
if !heardVersion(context.Background(), ix, m, t.Logf) {
|
||||
t.Fatal("the registry's published is not taken as a version")
|
||||
}
|
||||
if m.acked != c.acked {
|
||||
t.Errorf("acknowledged %d times, want %d", m.acked, c.acked)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user