milvus/internal/metastore/model/partition_test.go
sthuang a85e36bad2
fix: create collection task check failed after restart (#40982)
The fields and partitions information are stored and fetched with
different prefixes in the metadata. In the CreateCollectionTask, the
RootCoord checks the existing collection information against the
metadata. This check fails if the order of the fields or partitions info
differs, leading to an error after restarting Milvus. To resolve this,
we should use a map in the check logic to ensure consistency.

related: https://github.com/milvus-io/milvus/issues/40955

---------

Signed-off-by: shaoting-huang <shaoting.huang@zilliz.com>
2025-04-05 06:58:22 +08:00

55 lines
1.2 KiB
Go

package model
import (
"testing"
)
func TestCheckPartitionsEqual(t *testing.T) {
type args struct {
partitionsA []*Partition
partitionsB []*Partition
}
tests := []struct {
name string
args args
want bool
}{
{
// length not match.
args: args{
partitionsA: []*Partition{{PartitionName: "_default"}},
partitionsB: []*Partition{},
},
want: false,
},
{
args: args{
partitionsA: []*Partition{{PartitionName: "_default"}},
partitionsB: []*Partition{{PartitionName: "not_default"}},
},
want: false,
},
{
args: args{
partitionsA: []*Partition{{PartitionName: "_default"}, {PartitionName: "not_default"}},
partitionsB: []*Partition{{PartitionName: "_default"}, {PartitionName: "not_default"}},
},
want: true,
},
{
args: args{
partitionsA: []*Partition{{PartitionName: "not_default"}, {PartitionName: "_default"}},
partitionsB: []*Partition{{PartitionName: "_default"}, {PartitionName: "not_default"}},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CheckPartitionsEqual(tt.args.partitionsA, tt.args.partitionsB); got != tt.want {
t.Errorf("CheckPartitionsEqual() = %v, want %v", got, tt.want)
}
})
}
}