Files
ntfy/server/stream_registry_test.go
T
binwiederhier 62fb43b44b Make the cluster the owner of maintenance mode
The cluster now owns the maintenance state (Cluster.Maintenance) instead of the server keeping its own copy; the server keeps only the draining phase. Role() returns the role the node acts in (passive in maintenance mode), so /v1/ready says "role":"passive","maintenance":true. Cluster.HasActivePeer replaces the server's own walk over Members. A single-node server no longer logs about maintenance mode on every shutdown. The stream registry moves to its own file, with unit tests.
2026-10-23 19:42:18 +00:00

39 lines
970 B
Go

package server
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestStreamRegistry_CancelSomeClosesAndForgets(t *testing.T) {
r := newStreamRegistry()
ctxs := make([]context.Context, 0)
for i := 0; i < 5; i++ {
ctx, cancel := context.WithCancel(context.Background())
ctxs = append(ctxs, ctx)
r.Add(cancel)
}
require.Equal(t, 5, r.Len())
// Closed streams are forgotten at once, so the next call picks others
require.Equal(t, 2, r.CancelSome(2))
require.Equal(t, 3, r.Len())
require.Equal(t, 3, r.CancelSome(10))
require.Equal(t, 0, r.Len())
for _, ctx := range ctxs {
require.Error(t, ctx.Err())
}
}
func TestStreamRegistry_RemoveAfterCancelIsANop(t *testing.T) {
// A canceled stream's handler still calls Remove when it returns
r := newStreamRegistry()
_, cancel := context.WithCancel(context.Background())
id := r.Add(cancel)
require.Equal(t, 1, r.CancelSome(1))
r.Remove(id)
require.Equal(t, 0, r.Len())
}