mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Add lastIteratedId when setting merged heads
This commit is contained in:
parent
ea6ca799e7
commit
02b326cc90
3 changed files with 20 additions and 3 deletions
|
@ -3,6 +3,9 @@ package objecttree
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||
|
@ -10,8 +13,6 @@ import (
|
|||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testTreeContext struct {
|
||||
|
@ -123,6 +124,7 @@ func TestObjectTree(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, start.Unix(), ch.Timestamp)
|
||||
require.LessOrEqual(t, end.Unix(), ch.Timestamp)
|
||||
require.Equal(t, res.Added[0].Id, oTree.(*objectTree).tree.lastIteratedHeadId)
|
||||
})
|
||||
t.Run("timestamp is set correctly", func(t *testing.T) {
|
||||
someTs := time.Now().Add(time.Hour).Unix()
|
||||
|
@ -139,6 +141,7 @@ func TestObjectTree(t *testing.T) {
|
|||
ch, err := oTree.(*objectTree).changeBuilder.Unmarshall(res.Added[0], true)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ch.Timestamp, someTs)
|
||||
require.Equal(t, res.Added[0].Id, oTree.(*objectTree).tree.lastIteratedHeadId)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ func (t *Tree) AddMergedHead(c *Change) error {
|
|||
}
|
||||
}
|
||||
t.headIds = []string{c.Id}
|
||||
t.lastIteratedHeadId = c.Id
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,12 @@ package objecttree
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newChange(id string, snapshotId string, prevIds ...string) *Change {
|
||||
|
@ -26,6 +28,17 @@ func newSnapshot(id, snapshotId string, prevIds ...string) *Change {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTree_AddMergedHead(t *testing.T) {
|
||||
tr := new(Tree)
|
||||
_, _ = tr.Add(
|
||||
newSnapshot("root", ""),
|
||||
newChange("one", "root", "root"),
|
||||
)
|
||||
require.Equal(t, tr.lastIteratedHeadId, "one")
|
||||
tr.AddMergedHead(newChange("two", "root", "one"))
|
||||
require.Equal(t, tr.lastIteratedHeadId, "two")
|
||||
}
|
||||
|
||||
func TestTree_Add(t *testing.T) {
|
||||
t.Run("add first el", func(t *testing.T) {
|
||||
tr := new(Tree)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue