mesh/merge-gate head 7bd7a34090b2 merged into trunk f1906d9ffa6c — pass: builds messenger → novox; no bus step; every machine composes with the change as i…
mesh/repo-check head 7bd7a34090b2 merged into trunk f1906d9ffa6c — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Issue 1507: an ask was taken and queued for its burst window, the process was replaced before the flush, and
|
|
// the new process never offered it: the outbox is in memory, and an ask is offered only when it is taken. An
|
|
// open ask no channel has been sent is offered again, once, by the minute tick; one already sent is not.
|
|
|
|
// restarted is a new holder over the same stores and channels, as a replaced process is.
|
|
func restarted(t *testing.T, old *Holder, c *clock, st *memStore) *Holder {
|
|
t.Helper()
|
|
h := &Holder{Away: old.Away, Desk: old.Desk, Store: st, Now: c.now, Logf: t.Logf, Emit: old.Emit,
|
|
Bench: old.Bench, Asks: old.Asks, Node: old.Node, RootFree: old.RootFree, Zone: old.Zone, Publish: old.Publish}
|
|
h.init()
|
|
if err := h.Load(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
h.Start()
|
|
return h
|
|
}
|
|
|
|
func TestAnAskQueuedWhenTheProcessStoppedIsOfferedByTheNextProcess(t *testing.T) {
|
|
h, tg, dt, c, store, _ := newRouter(t)
|
|
st := h.Store.(*memStore)
|
|
link(h, store, c, "42", c.now().Add(-2*time.Hour))
|
|
submit(t, h, "mesh-config", heldAsk(c, "cfg-1"))
|
|
if len(tg.sends)+len(dt.sends) != 0 {
|
|
t.Fatalf("sent before the burst window")
|
|
}
|
|
// The process stops here, before the flush.
|
|
h2 := restarted(t, h, c, st)
|
|
for i := 0; i < 5; i++ {
|
|
c.pass(time.Minute)
|
|
stand(h2, c)
|
|
h2.Tick()
|
|
h2.Flush()
|
|
}
|
|
if n := len(tg.sends); n != 1 {
|
|
t.Fatalf("the ask was sent %d times on telegram, want once", n)
|
|
}
|
|
if n := len(dt.sends); n != 0 {
|
|
t.Fatalf("an approval ask was sent on the desk: %d", n)
|
|
}
|
|
}
|
|
|
|
func TestAnAskAlreadySentIsNotSentAgainAfterARestart(t *testing.T) {
|
|
h, tg, _, c, store, _ := newRouter(t)
|
|
st := h.Store.(*memStore)
|
|
link(h, store, c, "42", c.now().Add(-2*time.Hour))
|
|
submit(t, h, "mesh-config", heldAsk(c, "cfg-1"))
|
|
settle(h, c)
|
|
if len(tg.sends) != 1 {
|
|
t.Fatalf("not sent: %d", len(tg.sends))
|
|
}
|
|
h2 := restarted(t, h, c, st)
|
|
for i := 0; i < 5; i++ {
|
|
c.pass(time.Minute)
|
|
stand(h2, c)
|
|
h2.Tick()
|
|
h2.Flush()
|
|
}
|
|
if len(tg.sends) != 1 {
|
|
t.Fatalf("sent again after a restart: %d", len(tg.sends))
|
|
}
|
|
}
|