discovery-service/internal/state/state_test.go
Andrey Smirnov 619546696a feat: enable vtprotobuf, watch batching, more limits
Fixes 

Batch watch responses in a single batch so that client can quickly know
that initial snapshot got delivered.

Bump go.mod deps.

Implement more limits.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2021-09-23 17:58:45 +03:00

40 lines
976 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package state_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/talos-systems/discovery-service/internal/state"
)
func TestState(t *testing.T) {
now := time.Now()
st := state.NewState()
deletedClusters := st.GarbageCollect(now)
assert.Equal(t, 0, deletedClusters)
st.GetCluster("id1")
assert.NoError(t, st.GetCluster("id2").WithAffiliate("af1", func(affiliate *state.Affiliate) error {
affiliate.Update([]byte("data1"), now.Add(time.Minute))
return nil
}))
deletedClusters = st.GarbageCollect(now)
assert.Equal(t, 1, deletedClusters)
deletedClusters = st.GarbageCollect(now.Add(2 * time.Minute))
assert.Equal(t, 1, deletedClusters)
deletedClusters = st.GarbageCollect(now)
assert.Equal(t, 0, deletedClusters)
}