From c344e33c4b7218433c5d457945bb82ca28828cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kmie=C4=87?= Date: Thu, 6 Feb 2025 13:19:34 +0000 Subject: [PATCH 1/4] Replaced jq with a go script --- .../json_agency_config_parse_leader_id.go | 49 +++++++++++++++++++ test/on_failure.sh | 17 ++++--- 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go diff --git a/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go new file mode 100644 index 00000000..e85e3306 --- /dev/null +++ b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go @@ -0,0 +1,49 @@ +package main + +import ( + "encoding/json" + "fmt" + "io" + "os" +) + +func ExtractValue(input io.Reader) error { + var data map[string]interface{} + + decoder := json.NewDecoder(input) + if err := decoder.Decode(&data); err != nil { + return fmt.Errorf("failed to decode JSON: %w", err) + } + + configuration, ok := data["configuration"].(map[string]interface{}) + if !ok { + return fmt.Errorf("key 'configuration' not found or not an object") + } + pool, ok := configuration["pool"].(map[string]interface{}) + if !ok { + return fmt.Errorf("key 'pool' not found or not an array") + } + + leaderId, ok := data["leaderId"].(string) + if !ok { + return fmt.Errorf("key 'leaderId' not found or not a str") + } + if leaderId == "" { + return fmt.Errorf("key 'leaderId' not set") + } + + endpoint, ok := pool[leaderId].(string) + if !ok { + return fmt.Errorf("key '%s' not found or not a str", leaderId) + } + fmt.Println(endpoint) + + return nil +} + +func main() { + if err := ExtractValue(os.Stdin); err != nil { + fmt.Fprintf(os.Stderr, "JsonAgencyConfigParseError: %v\n and as a result the agency dump could not be created.\n", err) + + } +} diff --git a/test/on_failure.sh b/test/on_failure.sh index 22100a60..d43f1f62 100644 --- a/test/on_failure.sh +++ b/test/on_failure.sh @@ -30,16 +30,19 @@ if [ -n "${DUMP_AGENCY_ON_FAILURE}" ] && [ "${TEST_MODE}" = "cluster" ]; then # _api/agency/config returns leader endpoint with protocol that is usually not supported by curl AGENCY_CONFIG=$(bash -c "curl -k --no-progress-meter ${AUTH} ${ANY_ENDPOINT}/_api/agency/config") - LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | jq -r '.configuration.pool[.leaderId]' | cat) + # same as: jq -r '.configuration.pool[.leaderId]' + LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | go run ./test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go | cat) SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT="s/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//${PROTOCOL}:\/\//" LEADER_ENDPOINT=$(echo $LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL | sed $SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT) - echo "Leader agent endpoint: $LEADER_ENDPOINT" - DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE - mkdir -p $(dirname ${DUMP_FILE_PATH}) - AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state") - echo $AGENCY_DUMP > $DUMP_FILE_PATH - echo "Agency dump created at $(realpath $DUMP_FILE_PATH)" + if expr "$LEADER_ENDPOINT" : "^$PROTOCOL" > /dev/null; then + echo "Leader agent endpoint: $LEADER_ENDPOINT" + DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE + mkdir -p $(dirname ${DUMP_FILE_PATH}) + AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state") + echo $AGENCY_DUMP > $DUMP_FILE_PATH + echo "Agency dump created at $(realpath $DUMP_FILE_PATH)" + fi fi echo "\nV${MAJOR_VERSION} Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}"; From 33a1131b7058c0634081b8a5caaeb52a5ee485cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kmie=C4=87?= Date: Tue, 11 Feb 2025 13:20:26 +0000 Subject: [PATCH 2/4] zutano check --- collection.go | 4 +- .../json_agency_config_parse_leader_id.go | 20 ++ v2/tests/collections_document_read_test.go | 252 ++++++++++++++++++ 3 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 v2/tests/collections_document_read_test.go diff --git a/collection.go b/collection.go index c40922e5..c019d82e 100644 --- a/collection.go +++ b/collection.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2017-2021 ArangoDB GmbH, Cologne, Germany +// Copyright 2017-2025 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ type CollectionProperties struct { IsSmartChild bool `json:"isSmartChild,omitempty"` - InternalValidatorType *int `json:"internalValidatorType, omitempty"` + InternalValidatorType *int `json:"internalValidatorType,omitempty"` // Set to create a smart edge or vertex collection. // This requires ArangoDB Enterprise Edition. diff --git a/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go index e85e3306..2c8968ba 100644 --- a/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go +++ b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go @@ -1,3 +1,23 @@ +// +// DISCLAIMER +// +// Copyright 2025 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + package main import ( diff --git a/v2/tests/collections_document_read_test.go b/v2/tests/collections_document_read_test.go new file mode 100644 index 00000000..84bce908 --- /dev/null +++ b/v2/tests/collections_document_read_test.go @@ -0,0 +1,252 @@ +// +// DISCLAIMER +// +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package tests + +import ( + "context" + "fmt" + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/arangodb/go-driver/v2/arangodb" + "github.com/arangodb/go-driver/v2/arangodb/shared" +) + +func Test_CollectionDocumentsReadWithStringErrorCode(t *testing.T) { + Wrap(t, func(t *testing.T, client arangodb.Client) { + WithDatabase(t, client, nil, func(db arangodb.Database) { + WithCollection(t, db, nil, func(col arangodb.Collection) { + withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) { + + type DocWithNoCode struct { + Name string `json:"name"` + } + doc_with_no_code := DocWithNoCode{ + Name: "DocWithNoCode", + } + meta_with_no_code, err := col.CreateDocument(ctx, doc_with_no_code) + require.NoError(t, err) + + type DocWithCode struct { + Name string `json:"name"` + Error string `json:"error"` + Code string `json:"code"` + } + doc_with_code := DocWithCode{ + Name: "DocWithCode", + Code: "777", + } + meta_with_code, err := col.CreateDocument(ctx, doc_with_code) + require.NoError(t, err) + + doc_with_code_2 := DocWithCode{ + Name: "DocWithCode2", + Code: "222", + } + meta_with_code_2, err := col.CreateDocument(ctx, doc_with_code_2) + require.NoError(t, err) + + type DocWithResponselike struct { + Rev string `json:"_rev,omitempty"` + Key string `json:"_key,omitempty"` + Name string `json:"name"` + Error bool `json:"error,omitempty"` + Code int `json:"code,omitempty"` + ErrorMessage string `json:"errorMessage,omitempty"` + ErrorNum int `json:"errorNum,omitempty"` + } + doc_with_responselike := DocWithResponselike{ + Key: "key", + Name: "DocWithResponselike", + Code: 777, + } + meta_with_responselike, err := col.CreateDocument(ctx, doc_with_responselike) + require.NoError(t, err) + + _, _, _, _ = meta_with_no_code, meta_with_code, meta_with_code_2, meta_with_responselike + + t.Run("sanity check, proper doc should have no error", func(t *testing.T) { + var docRead DocWithNoCode + meta, err := col.ReadDocumentWithOptions(ctx, meta_with_no_code.Key, &docRead, nil) + require.NoError(t, err) + require.Equal(t, meta_with_no_code.Key, meta.Key) + }) + t.Run("sanity check, proper doc that doesn't exist should have error", func(t *testing.T) { + var docRead DocWithNoCode + _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) + require.Error(t, err) + require.Equal(t, 404, err.(shared.ArangoError).Code) + }) + t.Run("doc with code should have no error", func(t *testing.T) { + var docRead DocWithCode + meta, err := col.ReadDocumentWithOptions(ctx, meta_with_code.Key, &docRead, nil) + require.NoError(t, err) + require.Equal(t, "777", docRead.Code) + require.Equal(t, meta_with_code.Key, meta.Key) + }) + t.Run("doc with code that doesn't exist should have error", func(t *testing.T) { + var docRead DocWithCode + _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) + require.Error(t, err) + require.Equal(t, 404, err.(shared.ArangoError).Code) + }) + t.Run("doc with responselike format shouldn't have error", func(t *testing.T) { + var docRead DocWithResponselike + meta, err := col.ReadDocumentWithOptions(ctx, meta_with_responselike.Key, &docRead, nil) + require.NoError(t, err) + require.Equal(t, "key", docRead.Key) + require.Equal(t, meta_with_responselike.Key, meta.Key) + }) + t.Run("doc with responselike format that doesn't exist should have error", func(t *testing.T) { + var docRead DocWithResponselike + _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) + require.Error(t, err) + require.Equal(t, 404, err.(shared.ArangoError).Code) + }) + t.Run("docs with code should exist", func(t *testing.T) { + docsKeys := []DocWithRev{ + { + Key: meta_with_code.Key, + }, + { + Key: meta_with_code_2.Key, + }, + } + + resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) + require.NoError(t, err) + + var docRead DocWithCode + + _, err = resp.Read(&docRead) + require.NoError(t, err) + require.Equal(t, "777", docRead.Code) + + _, err = resp.Read(&docRead) + require.NoError(t, err) + require.Equal(t, "222", docRead.Code) + + }) + + t.Run("docs with code that doesn't exist should return empty", func(t *testing.T) { + docsKeys := []DocWithRev{ + { + Key: "404", + }, + { + Key: "404_2", + }, + } + + resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) + require.NoError(t, err) + + var docRead DocWithCode + + _, err = resp.Read(&docRead) + require.Error(t, err) + require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) + + _, err = resp.Read(&docRead) + require.Error(t, err) + require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) + + }) + + t.Run("docs with code mixed existence", func(t *testing.T) { + docsKeys := []DocWithRev{ + { + Key: "404", + }, + { + Key: meta_with_code_2.Key, + }, + } + + resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) + require.NoError(t, err) + + var docRead DocWithCode + _, err = resp.Read(&docRead) + + require.Error(t, err) + require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) + + _, err = resp.Read(&docRead) + require.NoError(t, err) + require.Equal(t, "222", docRead.Code) + + }) + }) + }) + }) + }) +} + +func Benchmark_CollectionDocumentsReadWithStringErrorCode(b *testing.B) { + WrapB(b, func(b *testing.B, client arangodb.Client) { + WithDatabase(b, client, nil, func(db arangodb.Database) { + WithCollection(b, db, nil, func(col arangodb.Collection) { + withContextT(b, defaultTestTimeout, func(ctx context.Context, tb testing.TB) { + type DocWithCode struct { + Name string `json:"name"` + Error string `json:"error"` + Code string `json:"code"` + } + + type Meta struct { + Key string `json:"_key,omitempty"` + } + + N := 100 + rng := rand.New(rand.NewSource(42)) + metas := []Meta{} + for i := range N { + doc_with_code := DocWithCode{ + Name: "DocWithCode", + Code: fmt.Sprintf("%d%03d", rng.Int()%1000, i), + Error: "error", + } + meta_with_code, _ := col.CreateDocument(ctx, doc_with_code) + metas = append(metas, Meta{Key: meta_with_code.Key}) + } + + b.Run("one_by_one", func(b *testing.B) { + var docRead DocWithCode + for i := range N { + _, _ = col.ReadDocumentWithOptions(ctx, metas[i].Key, &docRead, nil) + } + }) + + b.Run("bulk", func(b *testing.B) { + reader, _ := col.ReadDocumentsWithOptions(ctx, &metas, nil) + var docRead DocWithCode + for range N { + _, _ = reader.Read(&docRead) + } + }) + }) + }) + }) + }) +} From d8b2eb17ddfc3b500669f701d9f7e2bcdd8f029e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kmie=C4=87?= Date: Tue, 11 Feb 2025 13:36:35 +0000 Subject: [PATCH 3/4] Makefile fix --- Makefile | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Makefile b/Makefile index 6054a348..5b7cb399 100644 --- a/Makefile +++ b/Makefile @@ -80,20 +80,6 @@ endif TEST_NET := --net=host -SPACE := -TABV4 := $(SPACE) $(SPACE) $(SPACE) $(SPACE) -ifdef DUMP_AGENCY_ON_FAILURE - $(info Checking for jq...) - CHECK_JQ_INSTALLTION := $(shell jq --version 2>&1 >/dev/null | cat) - ifneq ($(CHECK_JQ_INSTALLTION),) - $(info ) - $(info Error: 'jq' is not installed. This check happens because DUMP_AGENCY_ON_FAILURE is set, and 'jq' is used during the creation of the agency dump. Verified for version jq==1.6. ) - $(info Try installing it with:) - $(info $(TABV4) sudo apt install jq) - $(info ) - $(error $(CHECK_JQ_INSTALLTION)) - endif -endif # Installation of jq is required for processing AGENCY_DUMP # ifdef DUMP_AGENCY_ON_FAILURE # CHECK_JQ_INSTALLTION := $(shell command -v jq >/dev/null 2>&1 || ( From 108fc15d14f120f1176ac176815bfd978587430b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kmie=C4=87?= Date: Tue, 11 Feb 2025 14:57:20 +0000 Subject: [PATCH 4/4] Git cleanup --- v2/tests/collections_document_read_test.go | 252 --------------------- 1 file changed, 252 deletions(-) delete mode 100644 v2/tests/collections_document_read_test.go diff --git a/v2/tests/collections_document_read_test.go b/v2/tests/collections_document_read_test.go deleted file mode 100644 index 84bce908..00000000 --- a/v2/tests/collections_document_read_test.go +++ /dev/null @@ -1,252 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package tests - -import ( - "context" - "fmt" - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/arangodb/go-driver/v2/arangodb" - "github.com/arangodb/go-driver/v2/arangodb/shared" -) - -func Test_CollectionDocumentsReadWithStringErrorCode(t *testing.T) { - Wrap(t, func(t *testing.T, client arangodb.Client) { - WithDatabase(t, client, nil, func(db arangodb.Database) { - WithCollection(t, db, nil, func(col arangodb.Collection) { - withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) { - - type DocWithNoCode struct { - Name string `json:"name"` - } - doc_with_no_code := DocWithNoCode{ - Name: "DocWithNoCode", - } - meta_with_no_code, err := col.CreateDocument(ctx, doc_with_no_code) - require.NoError(t, err) - - type DocWithCode struct { - Name string `json:"name"` - Error string `json:"error"` - Code string `json:"code"` - } - doc_with_code := DocWithCode{ - Name: "DocWithCode", - Code: "777", - } - meta_with_code, err := col.CreateDocument(ctx, doc_with_code) - require.NoError(t, err) - - doc_with_code_2 := DocWithCode{ - Name: "DocWithCode2", - Code: "222", - } - meta_with_code_2, err := col.CreateDocument(ctx, doc_with_code_2) - require.NoError(t, err) - - type DocWithResponselike struct { - Rev string `json:"_rev,omitempty"` - Key string `json:"_key,omitempty"` - Name string `json:"name"` - Error bool `json:"error,omitempty"` - Code int `json:"code,omitempty"` - ErrorMessage string `json:"errorMessage,omitempty"` - ErrorNum int `json:"errorNum,omitempty"` - } - doc_with_responselike := DocWithResponselike{ - Key: "key", - Name: "DocWithResponselike", - Code: 777, - } - meta_with_responselike, err := col.CreateDocument(ctx, doc_with_responselike) - require.NoError(t, err) - - _, _, _, _ = meta_with_no_code, meta_with_code, meta_with_code_2, meta_with_responselike - - t.Run("sanity check, proper doc should have no error", func(t *testing.T) { - var docRead DocWithNoCode - meta, err := col.ReadDocumentWithOptions(ctx, meta_with_no_code.Key, &docRead, nil) - require.NoError(t, err) - require.Equal(t, meta_with_no_code.Key, meta.Key) - }) - t.Run("sanity check, proper doc that doesn't exist should have error", func(t *testing.T) { - var docRead DocWithNoCode - _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) - require.Error(t, err) - require.Equal(t, 404, err.(shared.ArangoError).Code) - }) - t.Run("doc with code should have no error", func(t *testing.T) { - var docRead DocWithCode - meta, err := col.ReadDocumentWithOptions(ctx, meta_with_code.Key, &docRead, nil) - require.NoError(t, err) - require.Equal(t, "777", docRead.Code) - require.Equal(t, meta_with_code.Key, meta.Key) - }) - t.Run("doc with code that doesn't exist should have error", func(t *testing.T) { - var docRead DocWithCode - _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) - require.Error(t, err) - require.Equal(t, 404, err.(shared.ArangoError).Code) - }) - t.Run("doc with responselike format shouldn't have error", func(t *testing.T) { - var docRead DocWithResponselike - meta, err := col.ReadDocumentWithOptions(ctx, meta_with_responselike.Key, &docRead, nil) - require.NoError(t, err) - require.Equal(t, "key", docRead.Key) - require.Equal(t, meta_with_responselike.Key, meta.Key) - }) - t.Run("doc with responselike format that doesn't exist should have error", func(t *testing.T) { - var docRead DocWithResponselike - _, err := col.ReadDocumentWithOptions(ctx, "404", &docRead, nil) - require.Error(t, err) - require.Equal(t, 404, err.(shared.ArangoError).Code) - }) - t.Run("docs with code should exist", func(t *testing.T) { - docsKeys := []DocWithRev{ - { - Key: meta_with_code.Key, - }, - { - Key: meta_with_code_2.Key, - }, - } - - resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) - require.NoError(t, err) - - var docRead DocWithCode - - _, err = resp.Read(&docRead) - require.NoError(t, err) - require.Equal(t, "777", docRead.Code) - - _, err = resp.Read(&docRead) - require.NoError(t, err) - require.Equal(t, "222", docRead.Code) - - }) - - t.Run("docs with code that doesn't exist should return empty", func(t *testing.T) { - docsKeys := []DocWithRev{ - { - Key: "404", - }, - { - Key: "404_2", - }, - } - - resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) - require.NoError(t, err) - - var docRead DocWithCode - - _, err = resp.Read(&docRead) - require.Error(t, err) - require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) - - _, err = resp.Read(&docRead) - require.Error(t, err) - require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) - - }) - - t.Run("docs with code mixed existence", func(t *testing.T) { - docsKeys := []DocWithRev{ - { - Key: "404", - }, - { - Key: meta_with_code_2.Key, - }, - } - - resp, err := col.ReadDocumentsWithOptions(ctx, &docsKeys, nil) - require.NoError(t, err) - - var docRead DocWithCode - _, err = resp.Read(&docRead) - - require.Error(t, err) - require.Equal(t, 1202, err.(shared.ArangoError).ErrorNum) - - _, err = resp.Read(&docRead) - require.NoError(t, err) - require.Equal(t, "222", docRead.Code) - - }) - }) - }) - }) - }) -} - -func Benchmark_CollectionDocumentsReadWithStringErrorCode(b *testing.B) { - WrapB(b, func(b *testing.B, client arangodb.Client) { - WithDatabase(b, client, nil, func(db arangodb.Database) { - WithCollection(b, db, nil, func(col arangodb.Collection) { - withContextT(b, defaultTestTimeout, func(ctx context.Context, tb testing.TB) { - type DocWithCode struct { - Name string `json:"name"` - Error string `json:"error"` - Code string `json:"code"` - } - - type Meta struct { - Key string `json:"_key,omitempty"` - } - - N := 100 - rng := rand.New(rand.NewSource(42)) - metas := []Meta{} - for i := range N { - doc_with_code := DocWithCode{ - Name: "DocWithCode", - Code: fmt.Sprintf("%d%03d", rng.Int()%1000, i), - Error: "error", - } - meta_with_code, _ := col.CreateDocument(ctx, doc_with_code) - metas = append(metas, Meta{Key: meta_with_code.Key}) - } - - b.Run("one_by_one", func(b *testing.B) { - var docRead DocWithCode - for i := range N { - _, _ = col.ReadDocumentWithOptions(ctx, metas[i].Key, &docRead, nil) - } - }) - - b.Run("bulk", func(b *testing.B) { - reader, _ := col.ReadDocumentsWithOptions(ctx, &metas, nil) - var docRead DocWithCode - for range N { - _, _ = reader.Read(&docRead) - } - }) - }) - }) - }) - }) -}