40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// silentOnABus is the rollout's silent keys on a real bus, and the waits its watcher heard expire.
|
|
|
|
func hearsSilent(t *testing.T, heard <-chan silentWait, within time.Duration) (silentWait, bool) {
|
|
t.Helper()
|
|
select {
|
|
case w := <-heard:
|
|
return w, true
|
|
case <-time.After(within):
|
|
return silentWait{}, false
|
|
}
|
|
}
|
|
|
|
// A machine that never reports on its send is named silent when its key expires (issue 974, novox/hq ADR 0406 §5):
|
|
// the watcher names the plan, the tier and the machine, which a plan id or a machine name with a dot does not blur.
|
|
|
|
// A machine that reports in time is never named silent: the report deletes the key, and a delete is not an expiry.
|
|
|
|
// A send made again to a machine puts its key again with the full time, and only the last send's key can expire.
|
|
|
|
func TestASilentKeyIsParsedFromTheRightOfTheNode(t *testing.T) {
|
|
for _, w := range []silentWait{{"plan-1", 0, "ace"}, {"a.b", 12, "g14"}} {
|
|
got, ok := parseSilentKey(silentKey(w))
|
|
if !ok || got != w {
|
|
t.Errorf("%+v became %+v (%v)", w, got, ok)
|
|
}
|
|
}
|
|
for _, bad := range []string{"", "plan", "plan.x.ace", "plan..ace", ".1.ace"} {
|
|
if _, ok := parseSilentKey(bad); ok {
|
|
t.Errorf("%q was read as a wait", bad)
|
|
}
|
|
}
|
|
}
|