This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


The following commit(s) were added to refs/heads/main by this push:
     new 43638d67 Fix comparison issues in TopN test cases (#839)
43638d67 is described below

commit 43638d676e2210f6d796404dcc9414effbab8c2f
Author: peachisai <[email protected]>
AuthorDate: Thu Nov 6 22:11:31 2025 +0800

    Fix comparison issues in TopN test cases (#839)
---
 CHANGES.md                   |  1 +
 banyand/measure/topn_test.go | 31 +++++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 53c23f35..3d64f7d9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -69,6 +69,7 @@ Release Notes.
 - Fix memory leaks and OOM issues in streaming processing by implementing 
deduplication logic in priority queues and improving sliding window memory 
management.
 - Fix etcd prefix matching any key that starts with this prefix.
 - Fix the sorting timestamps issue of the measure model when there are more 
than one segment.
+- Fix comparison issues in TopN test cases
 
 ### Document
 
diff --git a/banyand/measure/topn_test.go b/banyand/measure/topn_test.go
index ec8014c8..385d39c5 100644
--- a/banyand/measure/topn_test.go
+++ b/banyand/measure/topn_test.go
@@ -20,7 +20,10 @@ package measure
 import (
        "testing"
 
+       "github.com/google/go-cmp/cmp"
        "github.com/stretchr/testify/require"
+       "google.golang.org/protobuf/proto"
+       "google.golang.org/protobuf/testing/protocmp"
 
        modelv1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 )
@@ -72,6 +75,21 @@ func TestTopNValue_MarshalUnmarshal(t *testing.T) {
 
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
+                       // clone the original value
+                       originalValueName := tt.topNVal.valueName
+                       originalEntityTagNames := make([]string, 
len(tt.topNVal.entityTagNames))
+                       copy(originalEntityTagNames, tt.topNVal.entityTagNames)
+                       originalValues := make([]int64, len(tt.topNVal.values))
+                       copy(originalValues, tt.topNVal.values)
+
+                       originalEntities := make([][]*modelv1.TagValue, 
len(tt.topNVal.entities))
+                       for i, entityGroup := range tt.topNVal.entities {
+                               originalEntities[i] = make([]*modelv1.TagValue, 
len(entityGroup))
+                               for j, tagValue := range entityGroup {
+                                       originalEntities[i][j] = 
proto.Clone(tagValue).(*modelv1.TagValue)
+                               }
+                       }
+
                        // Marshal the topNValue
                        dst, err := tt.topNVal.marshal(nil)
                        require.NoError(t, err)
@@ -82,10 +100,15 @@ func TestTopNValue_MarshalUnmarshal(t *testing.T) {
                        require.NoError(t, err)
 
                        // Compare the original and decoded topNValue
-                       require.Equal(t, tt.topNVal.valueName, 
tt.topNVal.valueName)
-                       require.Equal(t, tt.topNVal.entityTagNames, 
tt.topNVal.entityTagNames)
-                       require.Equal(t, tt.topNVal.values, tt.topNVal.values)
-                       require.Equal(t, tt.topNVal.entities, 
tt.topNVal.entities)
+                       require.Equal(t, originalValueName, 
tt.topNVal.valueName)
+                       require.Equal(t, originalEntityTagNames, 
tt.topNVal.entityTagNames)
+                       require.Equal(t, originalValues, tt.topNVal.values)
+                       diff := cmp.Diff(originalEntities, tt.topNVal.entities, 
protocmp.Transform())
+                       require.True(t,
+                               diff == "",
+                               "entities differ: %s",
+                               diff,
+                       )
                })
        }
 }

Reply via email to