milvus/internal/coordinator/snmanager/streaming_node_manager_test.go
Zhen Ye af0881ee5d
fix: timetick cannot push forward when upgrading (#42567)
issue #42492

- streamingcoord start before old rootcoord.
- streaming balancer will check the node session synchronously to avoid
redundant operation when cluster startup.
- ddl operation will check if streaming enabled, if the streaming is not
enabled, it will use msgstream.
- msgstream will initialize if streaming is not enabled, and stop when
streaming is enabled.

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2025-06-10 14:52:42 +08:00

76 lines
1.9 KiB
Go

package snmanager
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/milvus-io/milvus/internal/mocks/streamingcoord/server/mock_balancer"
"github.com/milvus-io/milvus/pkg/v2/streaming/util/types"
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
)
type pChannelInfoAssigned struct {
version typeutil.VersionInt64Pair
pchannels []types.PChannelInfoAssigned
}
func TestStreamingNodeManager(t *testing.T) {
m := newStreamingNodeManager()
b := mock_balancer.NewMockBalancer(t)
ch := make(chan pChannelInfoAssigned, 1)
b.EXPECT().WatchChannelAssignments(mock.Anything, mock.Anything).Run(
func(ctx context.Context, cb func(typeutil.VersionInt64Pair, []types.PChannelInfoAssigned) error) {
for {
select {
case <-ctx.Done():
return
case p := <-ch:
cb(p.version, p.pchannels)
}
}
})
b.EXPECT().RegisterStreamingEnabledNotifier(mock.Anything).Return()
m.SetBalancerReady(b)
streamingNodes := m.GetStreamingQueryNodeIDs()
assert.Empty(t, streamingNodes)
ch <- pChannelInfoAssigned{
version: typeutil.VersionInt64Pair{
Global: 1,
Local: 1,
},
pchannels: []types.PChannelInfoAssigned{
{
Channel: types.PChannelInfo{Name: "a_test", Term: 1},
Node: types.StreamingNodeInfo{ServerID: 1, Address: "localhost:1"},
},
},
}
listener := m.ListenNodeChanged()
err := listener.Wait(context.Background())
assert.NoError(t, err)
node := m.GetWALLocated("a_test")
assert.Equal(t, node, int64(1))
streamingNodes = m.GetStreamingQueryNodeIDs()
assert.Equal(t, len(streamingNodes), 1)
assert.NoError(t, m.RegisterStreamingEnabledListener(context.Background(), NewStreamingReadyNotifier()))
}
func TestStreamingReadyNotifier(t *testing.T) {
n := NewStreamingReadyNotifier()
assert.False(t, n.IsReady())
n.inner.Cancel()
<-n.Ready()
assert.True(t, n.IsReady())
n.Release()
assert.True(t, n.IsReady())
}