1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00

Fix params and update test

This commit is contained in:
mcrakhman 2023-12-05 20:28:44 +01:00
parent b7007df2f6
commit fe0147ee17
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
2 changed files with 22 additions and 12 deletions

View file

@ -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{

View file

@ -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)
}