From 771e608fe778b2a88841531aaf3c0d1f785c163b Mon Sep 17 00:00:00 2001 From: Pavel Antonov <antonov@perx.ru> Date: Wed, 14 Feb 2024 10:56:35 +0000 Subject: [PATCH] =?UTF-8?q?fix(sync):=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20"received=20message=20larger=20than?= =?UTF-8?q?=20max".=20=D0=9F=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=20=D1=83=D1=81=D0=BA=D0=BE=D1=80=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #PRXS-2026 (cherry picked from commit 083aaf1f363093219bb58f67b1accbc5a31f097a) 2408d53a Рсправлена возникающая РїСЂРё синхронизации ошибка "find destination items: grpc:... --- pkg/items/dummy.go | 17 +++++++++++++++++ pkg/items/pagination.go | 5 +++++ pkg/items/pagination_test.go | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 pkg/items/dummy.go create mode 100644 pkg/items/pagination_test.go diff --git a/pkg/items/dummy.go b/pkg/items/dummy.go new file mode 100644 index 00000000..fc1f725a --- /dev/null +++ b/pkg/items/dummy.go @@ -0,0 +1,17 @@ +package items + +import "context" + +type FindResultDummy struct { + Items []*Item + Total int + Error error +} +type Dummy struct { + Items + FindResult *FindResultDummy +} + +func (d *Dummy) Find(_ context.Context, _, _, _ string, _ *Filter, _ ...*FindOptions) ([]*Item, int, error) { + return d.FindResult.Items, d.FindResult.Total, d.FindResult.Error +} diff --git a/pkg/items/pagination.go b/pkg/items/pagination.go index 6fe197d7..84fac6da 100644 --- a/pkg/items/pagination.go +++ b/pkg/items/pagination.go @@ -128,6 +128,11 @@ func (b *BatchProcessor) Do(ctx context.Context, f func(batch []*Item) error) (i return 0, err } + // РЅР° случай, РєРѕРіРґР° первый запрос вернул 0 элементов + if len(batch) == 0 { + break + } + if err = f(batch); err != nil { return 0, err } diff --git a/pkg/items/pagination_test.go b/pkg/items/pagination_test.go new file mode 100644 index 00000000..bf13af39 --- /dev/null +++ b/pkg/items/pagination_test.go @@ -0,0 +1,35 @@ +package items + +import ( + "context" + "testing" + + "git.perx.ru/perxis/perxis-go/pkg/environments" + "git.perx.ru/perxis/perxis-go/pkg/options" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestBatchProcessor(t *testing.T) { + + itemssvc := &Dummy{FindResult: &FindResultDummy{Items: nil, Total: 0, Error: nil}} + + b := &BatchProcessor{ + Items: itemssvc, + SpaceID: "sp", + EnvID: environments.DefaultEnvironment, + CollectionID: "col", + FindOptions: &FindOptions{ + Regular: true, + Hidden: true, + Templates: true, + FindOptions: *options.NewFindOptions(0, 10), + }, + Filter: NewFilter("a > 5"), + } + + var counter int + _, err := b.Do(context.Background(), func(batch []*Item) error { counter++; return nil }) + require.NoError(t, err) + assert.Equal(t, 0, counter) +} -- GitLab