1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/commonspace/headsync/remotediff_test.go
2023-12-05 20:28:44 +01:00

50 lines
1.1 KiB
Go

package headsync
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/anyproto/any-sync/app/ldiff"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
)
func TestRemote(t *testing.T) {
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),
}
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, 99000)
assert.Len(t, changedIds, 0)
assert.Len(t, removedIds, 0)
}
type mockClient struct {
l ldiff.Diff
}
func (m *mockClient) HeadSync(ctx context.Context, in *spacesyncproto.HeadSyncRequest) (*spacesyncproto.HeadSyncResponse, error) {
return HandleRangeRequest(ctx, m.l, in)
}