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:
parent
b7007df2f6
commit
fe0147ee17
2 changed files with 22 additions and 12 deletions
|
@ -71,8 +71,9 @@ func (r *remote) Ranges(ctx context.Context, ranges []ldiff.Range, resBuf []ldif
|
||||||
pbRanges := make([]*spacesyncproto.HeadSyncRange, 0, len(ranges))
|
pbRanges := make([]*spacesyncproto.HeadSyncRange, 0, len(ranges))
|
||||||
for _, rg := range ranges {
|
for _, rg := range ranges {
|
||||||
pbRanges = append(pbRanges, &spacesyncproto.HeadSyncRange{
|
pbRanges = append(pbRanges, &spacesyncproto.HeadSyncRange{
|
||||||
From: rg.From,
|
From: rg.From,
|
||||||
To: rg.To,
|
To: rg.To,
|
||||||
|
Elements: rg.Elements,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
req := &spacesyncproto.HeadSyncRequest{
|
req := &spacesyncproto.HeadSyncRequest{
|
||||||
|
|
|
@ -3,31 +3,40 @@ package headsync
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anyproto/any-sync/app/ldiff"
|
"testing"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestRemote(t *testing.T) {
|
||||||
ldLocal := ldiff.New(8, 8)
|
ldLocal := ldiff.New(32, 256)
|
||||||
ldRemote := ldiff.New(8, 8)
|
ldRemote := ldiff.New(32, 256)
|
||||||
for i := 0; i < 100; i++ {
|
var (
|
||||||
|
localEls []ldiff.Element
|
||||||
|
remoteEls []ldiff.Element
|
||||||
|
)
|
||||||
|
|
||||||
|
for i := 0; i < 100000; i++ {
|
||||||
el := ldiff.Element{
|
el := ldiff.Element{
|
||||||
Id: fmt.Sprint(i),
|
Id: fmt.Sprint(i),
|
||||||
Head: fmt.Sprint(i),
|
Head: fmt.Sprint(i),
|
||||||
}
|
}
|
||||||
ldRemote.Set(el)
|
remoteEls = append(remoteEls, el)
|
||||||
if i%10 != 0 {
|
if i%100 == 0 {
|
||||||
ldLocal.Set(el)
|
localEls = append(localEls, el)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ldLocal.Set(localEls...)
|
||||||
|
ldRemote.Set(remoteEls...)
|
||||||
|
|
||||||
rd := NewRemoteDiff("1", &mockClient{l: ldRemote})
|
rd := NewRemoteDiff("1", &mockClient{l: ldRemote})
|
||||||
newIds, changedIds, removedIds, err := ldLocal.Diff(context.Background(), rd)
|
newIds, changedIds, removedIds, err := ldLocal.Diff(context.Background(), rd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, newIds, 10)
|
assert.Len(t, newIds, 99000)
|
||||||
assert.Len(t, changedIds, 0)
|
assert.Len(t, changedIds, 0)
|
||||||
assert.Len(t, removedIds, 0)
|
assert.Len(t, removedIds, 0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue