The operator channel kept at most three asks of one asker offered and held its oldest back behind newer ones, so asks waited unseen (the pipeline's proposal behind two mailu asks). It keeps no count any more and holds nothing back: every ask is offered when it is raised, and lapses at its expiry or ends at its answer. An ask held back before the change is offered again at the router's next tick; ask-again offers one so and holds nothing back in its place. Builds: design 47 G A-424
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
|
)
|
|
|
|
// Design 47 G A-424: the channel keeps no count of an asker's open asks and holds none back: every ask is offered when it is
|
|
// raised, five of one asker at once too, and none is refused. An ask held back before the change is offered again at the
|
|
// router's next tick, with new tickets; ask-again offers one now and holds nothing back in its place.
|
|
func TestEveryAskIsOfferedAndOneHeldBackBeforeIsOfferedAgain(t *testing.T) {
|
|
h, _, _, c, store, w := newRouter(t)
|
|
link(h, store, c, "42", c.now().Add(-2*time.Hour))
|
|
state := func(id string) string { return store.asks["mesh-delivery."+id].State }
|
|
for i, id := range []string{"d-1", "d-2", "d-3", "d-4", "d-5"} {
|
|
a := ackAsk(c, id)
|
|
a.About = "about-" + string(rune('1'+i))
|
|
submit(t, h, "mesh-delivery", a)
|
|
c.pass(time.Second)
|
|
settle(h, c)
|
|
}
|
|
for _, id := range []string{"d-1", "d-2", "d-3", "d-4", "d-5"} {
|
|
if state(id) != StateOpen || len(store.asks["mesh-delivery."+id].Tickets) == 0 {
|
|
t.Fatalf("%s is %s with %d tickets: every ask is offered", id, state(id), len(store.asks["mesh-delivery."+id].Tickets))
|
|
}
|
|
}
|
|
// One held back before the change, as the store kept it.
|
|
key := "mesh-delivery.d-2"
|
|
got, rev, _ := store.GetAsk(key)
|
|
got.State, got.Tickets, got.HeldBackSince = StateHeldBack, nil, c.now()
|
|
rev, err := store.UpdateAsk(key, *got, rev)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
h.keepAsk(key, *got, rev)
|
|
if a := h.AskAgain("mesh-delivery.d-1"); !strings.Contains(a.Error, "not held back") {
|
|
t.Errorf("ask-again of an offered ask: %+v", a)
|
|
}
|
|
if a := h.AskAgain("mesh-delivery.d-none"); a.Error == "" || a.State != "" {
|
|
t.Errorf("ask-again of an ask the router holds none of: %+v", a)
|
|
}
|
|
h.Tick()
|
|
settle(h, c)
|
|
if rec := store.asks[key]; rec.State != StateOpen || len(rec.Tickets) == 0 || !rec.HeldBackSince.IsZero() {
|
|
t.Fatalf("the ask held back before the change, after a tick: %+v", rec)
|
|
}
|
|
for _, id := range []string{"d-1", "d-3", "d-4", "d-5"} {
|
|
if state(id) != StateOpen {
|
|
t.Errorf("%s is %s after the held-back one was offered: nothing is held back in its place", id, state(id))
|
|
}
|
|
}
|
|
for _, wt := range w.of("mesh-delivery") {
|
|
if wt.Outcome == occ.OutcomeRefused {
|
|
t.Errorf("refused: %+v", wt)
|
|
}
|
|
}
|
|
}
|
|
|
|
func mustJSON(v any) []byte { raw, _ := json.Marshal(v); return raw }
|