From fe0147ee17ddd93aecbdc98fe24fd075e47dc15d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Tue, 5 Dec 2023 20:28:44 +0100 Subject: [PATCH] Fix params and update test --- commonspace/headsync/remotediff.go | 5 +++-- commonspace/headsync/remotediff_test.go | 29 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/commonspace/headsync/remotediff.go b/commonspace/headsync/remotediff.go index f134fcd5..1748d3c1 100644 --- a/commonspace/headsync/remotediff.go +++ b/commonspace/headsync/remotediff.go @@ -71,8 +71,9 @@ func (r *remote) Ranges(ctx context.Context, ranges []ldiff.Range, resBuf []ldif pbRanges := make([]*spacesyncproto.HeadSyncRange, 0, len(ranges)) for _, rg := range ranges { pbRanges = append(pbRanges, &spacesyncproto.HeadSyncRange{ - From: rg.From, - To: rg.To, + From: rg.From, + To: rg.To, + Elements: rg.Elements, }) } req := &spacesyncproto.HeadSyncRequest{ diff --git a/commonspace/headsync/remotediff_test.go b/commonspace/headsync/remotediff_test.go index 99f80840..40e0a119 100644 --- a/commonspace/headsync/remotediff_test.go +++ b/commonspace/headsync/remotediff_test.go @@ -3,31 +3,40 @@ package headsync import ( "context" "fmt" - "github.com/anyproto/any-sync/app/ldiff" - "github.com/anyproto/any-sync/commonspace/spacesyncproto" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" + + "github.com/anyproto/any-sync/app/ldiff" + "github.com/anyproto/any-sync/commonspace/spacesyncproto" ) func TestRemote(t *testing.T) { - ldLocal := ldiff.New(8, 8) - ldRemote := ldiff.New(8, 8) - for i := 0; i < 100; i++ { + ldLocal := ldiff.New(32, 256) + ldRemote := ldiff.New(32, 256) + var ( + localEls []ldiff.Element + remoteEls []ldiff.Element + ) + + for i := 0; i < 100000; i++ { el := ldiff.Element{ Id: fmt.Sprint(i), Head: fmt.Sprint(i), } - ldRemote.Set(el) - if i%10 != 0 { - ldLocal.Set(el) + remoteEls = append(remoteEls, el) + if i%100 == 0 { + localEls = append(localEls, el) } } + ldLocal.Set(localEls...) + ldRemote.Set(remoteEls...) rd := NewRemoteDiff("1", &mockClient{l: ldRemote}) newIds, changedIds, removedIds, err := ldLocal.Diff(context.Background(), rd) require.NoError(t, err) - assert.Len(t, newIds, 10) + assert.Len(t, newIds, 99000) assert.Len(t, changedIds, 0) assert.Len(t, removedIds, 0) }