A new controller's grants reached the bus only after its gate, so the buckets it newly writes were refused until then. At start it now sends the bus's machine the user list alone, every build there kept.
74 lines
3.1 KiB
Go
74 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// 1800 (1): a controller starting with the bus's list behind its own sends the bus's machine once, before anything
|
|
// that writes its buckets starts.
|
|
func TestAStartingControllerSendsItsGrantsBeforeItWrites(t *testing.T) {
|
|
var order []string
|
|
c := ownGrantsCarrier{
|
|
behind: func(context.Context) (string, bool, error) { return "novox", true, nil },
|
|
send: func(_ context.Context, holder string) error { order = append(order, "send "+holder); return nil },
|
|
}
|
|
startWithOwnGrants(t.Context(), c, func() { order = append(order, "writers") })
|
|
if strings.Join(order, ", ") != "send novox, writers" {
|
|
t.Fatalf("the start did %v", order)
|
|
}
|
|
}
|
|
|
|
// 1800 (3), (4): no send when the list is current or there is no bus with a list; one that cannot be read or sent is
|
|
// said once, and the controller goes on.
|
|
func TestAStartingControllerSendsNothingWhenTheListIsCurrentAndGoesOnWhenRefused(t *testing.T) {
|
|
sends := 0
|
|
send := func(context.Context, string) error { sends++; return nil }
|
|
for _, c := range []ownGrantsCarrier{
|
|
{behind: func(context.Context) (string, bool, error) { return "novox", false, nil }, send: send},
|
|
{behind: func(context.Context) (string, bool, error) { return "", true, nil }, send: send},
|
|
} {
|
|
if said := c.carry(t.Context()); said != "" || sends != 0 {
|
|
t.Fatalf("a current list sent %d and said %q", sends, said)
|
|
}
|
|
}
|
|
refused := ownGrantsCarrier{behind: func(context.Context) (string, bool, error) { return "novox", true, nil },
|
|
send: func(context.Context, string) error { return errNotGrantsOnly }}
|
|
went := false
|
|
startWithOwnGrants(t.Context(), refused, func() { went = true })
|
|
if !went {
|
|
t.Fatal("a refused send stopped the controller")
|
|
}
|
|
if said := refused.carry(t.Context()); !strings.Contains(said, "could not be sent to novox") ||
|
|
!strings.Contains(said, errNotGrantsOnly.Error()) {
|
|
t.Fatalf("a refused send is said as %q", said)
|
|
}
|
|
unread := ownGrantsCarrier{behind: func(context.Context) (string, bool, error) { return "", false, errors.New("no store") },
|
|
send: send}
|
|
if said := unread.carry(t.Context()); !strings.Contains(said, "cannot be read") || sends != 0 {
|
|
t.Fatalf("an unread list: sent %d, said %q", sends, said)
|
|
}
|
|
}
|
|
|
|
// 1800 (2): the start's send is the grants step's: composed with every build of the bus's machine kept at the one it
|
|
// runs, so the declaration differs from its last only by the user list (and is refused unsent otherwise,
|
|
// errNotGrantsOnly, release.go), whatever a running plan registered since.
|
|
func TestAStartingControllersSendKeepsEveryBuildOfTheBusMachine(t *testing.T) {
|
|
was := sendRollout
|
|
t.Cleanup(func() { sendRollout = was })
|
|
var kept bool
|
|
var named []string
|
|
sendRollout = func(ctx context.Context, _ *stores, names []string) ([]string, error) {
|
|
kept, named = everyBuildKept(ctx, "novox"), names
|
|
return names, nil
|
|
}
|
|
if err := ownGrantsOf(nil).send(t.Context(), "novox"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !kept || len(named) != 1 || named[0] != "novox" {
|
|
t.Fatalf("the start's send keeps every build: %v, names %v", kept, named)
|
|
}
|
|
}
|