kenhuuu commented on code in PR #3397:
URL: https://github.com/apache/tinkerpop/pull/3397#discussion_r3151104275
##########
gremlin-go/driver/traversal_test.go:
##########
@@ -542,6 +542,151 @@ func TestTraversal(t *testing.T) {
})
}
+func TestTraversalNextValue(t *testing.T) {
+ // Helper to create a closed ResultSet pre-populated with results.
+ makeResultSet := func(results ...*Result) ResultSet {
+ rs := newChannelResultSetCapacity(len(results) +
1).(*channelResultSet)
+ for _, r := range results {
+ rs.channel <- r
+ }
+ rs.channelMutex.Lock()
+ rs.closed = true
+ close(rs.channel)
+ rs.channelMutex.Unlock()
+ return rs
+ }
+
+ t.Run("unrolls Traverser with bulk > 1", func(t *testing.T) {
+ rs := makeResultSet(
+ &Result{&Traverser{Bulk: 3, Value: "marko"}},
+ )
+ trav := &Traversal{results: rs}
+
+ var values []interface{}
+ for {
+ val, ok, err := trav.nextValue()
+ assert.Nil(t, err)
+ if !ok {
+ break
+ }
+ values = append(values, val)
+ }
+ assert.Equal(t, []interface{}{"marko", "marko", "marko"},
values)
+ })
+
+ t.Run("unrolls Traverser with bulk == 1", func(t *testing.T) {
+ rs := makeResultSet(
+ &Result{&Traverser{Bulk: 1, Value: 42}},
+ )
+ trav := &Traversal{results: rs}
+
+ val, ok, err := trav.nextValue()
+ assert.Nil(t, err)
+ assert.True(t, ok)
+ assert.Equal(t, 42, val)
+
+ // Should be exhausted
+ _, ok, err = trav.nextValue()
+ assert.Nil(t, err)
+ assert.False(t, ok)
+ })
+
+ t.Run("handles raw non-Traverser results", func(t *testing.T) {
+ rs := makeResultSet(
+ &Result{"hello"},
+ &Result{int32(99)},
+ )
+ trav := &Traversal{results: rs}
+
+ val, ok, err := trav.nextValue()
+ assert.Nil(t, err)
+ assert.True(t, ok)
+ assert.Equal(t, "hello", val)
+
+ val, ok, err = trav.nextValue()
+ assert.Nil(t, err)
+ assert.True(t, ok)
+ assert.Equal(t, int32(99), val)
+
+ _, ok, err = trav.nextValue()
+ assert.Nil(t, err)
+ assert.False(t, ok)
+ })
+
+ t.Run("handles mixed Traverser and raw results", func(t *testing.T) {
Review Comment:
Is this test valuable? In what situation would this happen? The reason I'm
asking this question is, if someone were to make a change that somehow broke
this test, they would assume this is the appropriate behavior. But in my mind,
results should either be bulked or not bulked, but not a mix of the two?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]