Files
mesh-controller/internal/broker/state_keyttl_test.go
T

32 lines
1.4 KiB
Go

package broker
import (
"testing"
"time"
)
// 1154/AC2: a bucket declared with key-ttl is asserted with the marker age that allows a time to live per message;
// one without is asserted with none.
func TestAKeyTTLBucketIsAssertedWithTheMarkerAge(t *testing.T) { // 1154/AC2
with := BucketConfig(Bucket{Module: "mesh-delivery-watchman", Name: "pulse", KeyTTL: true}, 0)
if with.LimitMarkerTTL != KeyTTLMarkerTTL || KeyTTLMarkerTTL <= 0 {
t.Fatalf("a key-ttl bucket is asserted with marker age %v, want %v", with.LimitMarkerTTL, KeyTTLMarkerTTL)
}
without := BucketConfig(Bucket{Module: "mesh-delivery-watchman", Name: "stuck"}, 0)
if without.LimitMarkerTTL != 0 {
t.Fatalf("a bucket without key-ttl is asserted with marker age %v, want none", without.LimitMarkerTTL)
}
if with.Bucket != "mesh-delivery-watchman_pulse" || with.History != 1 || with.MaxBytes != StateMaxBytes {
t.Fatalf("the rest of the options changed: %+v", with)
}
}
// 1154/AC3: a bucket that already allows a time to live per message keeps it when its owner no longer says key-ttl,
// because the server refuses to turn it off; it is not asserted without it.
func TestABucketThatAllowsAKeyTTLKeepsIt(t *testing.T) { // 1154/AC3
got := BucketConfig(Bucket{Module: "m", Name: "s"}, 5*time.Minute)
if got.LimitMarkerTTL != 5*time.Minute {
t.Fatalf("a bucket that held marker age 5m is asserted with %v, which the server refuses", got.LimitMarkerTTL)
}
}