From 599398abb6e08482797b157b72929540025297b1 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 27 Mar 2024 22:24:55 +0100 Subject: [PATCH] Fix cursor batch --- test/backup_test.go | 7 ++++++- v2/CHANGELOG.md | 1 + v2/arangodb/cursor_impl.go | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/backup_test.go b/test/backup_test.go index 614bca4f..a71458f5 100644 --- a/test/backup_test.go +++ b/test/backup_test.go @@ -30,6 +30,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + driver "github.com/arangodb/go-driver" ) @@ -800,7 +802,10 @@ func TestBackupRestoreWithViews(t *testing.T) { if err != nil { t.Fatalf("Failed to create query: %s", describe(err)) } - defer cursor.Close() + defer func(cursor driver.Cursor) { + err := cursor.Close() + require.NoError(t, err) + }(cursor) var numDocumentsInView int _, err = cursor.ReadDocument(ctx, &numDocumentsInView) diff --git a/v2/CHANGELOG.md b/v2/CHANGELOG.md index d3357cca..65222db0 100644 --- a/v2/CHANGELOG.md +++ b/v2/CHANGELOG.md @@ -20,6 +20,7 @@ - Admin Cluster API support - Set Licence API support - Transparent compression of requests and responses (ArangoDBConfiguration.Compression) +- Fix Cursor batch ## [2.0.3](https://github.com/arangodb/go-driver/tree/v2.0.3) (2023-10-31) diff --git a/v2/arangodb/cursor_impl.go b/v2/arangodb/cursor_impl.go index c1cdc0cc..656d8d40 100644 --- a/v2/arangodb/cursor_impl.go +++ b/v2/arangodb/cursor_impl.go @@ -89,10 +89,10 @@ func (c *cursor) CloseWithContext(ctx context.Context) error { if err != nil { return err } + c.closed = true switch code := resp.Code(); code { case http.StatusAccepted: - c.closed = true c.data = cursorData{} return nil default: @@ -182,13 +182,16 @@ func (c *cursor) getNextBatch(ctx context.Context, retryBatchID string) error { c.retryData.currentBatchID = c.data.NextBatchID } - resp, err := connection.CallPost(ctx, c.db.connection(), url, &c.data, nil, c.db.modifiers...) + var data cursorData + + resp, err := connection.CallPost(ctx, c.db.connection(), url, &data, nil, c.db.modifiers...) if err != nil { return err } switch code := resp.Code(); code { case http.StatusOK: + c.data = data return nil default: return shared.NewResponseStruct().AsArangoErrorWithCode(code)