1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 17:45:03 +09:00

Fix all old object tree tests

This commit is contained in:
mcrakhman 2024-11-25 18:48:59 +01:00
parent 296cf7144a
commit 3c6284c750
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
4 changed files with 15 additions and 8 deletions

View file

@ -229,8 +229,9 @@ func prepareAclList(t *testing.T) (list.AclList, *accountdata.AccountKeys) {
}
func prepareHistoryTreeDeps(t *testing.T, aclList list.AclList) (*MockChangeCreator, objectTreeDeps) {
store := newStore(ctx, t)
changeCreator := NewMockChangeCreator(store)
changeCreator := NewMockChangeCreator(func() anystore.DB {
return newStore(ctx, t)
})
treeStorage := changeCreator.CreateNewTreeStorage(t, "0", aclList.Head().Id, false)
root, _ := treeStorage.Root(ctx)
changeBuilder := &nonVerifiableChangeBuilder{
@ -256,8 +257,9 @@ func prepareContext(
objTreeBuilder BuildObjectTreeFunc,
isDerived bool,
additionalChanges func(changeCreator *MockChangeCreator) RawChangesPayload) testTreeContext {
store := newStore(ctx, t)
changeCreator := NewMockChangeCreator(store)
changeCreator := NewMockChangeCreator(func() anystore.DB {
return newStore(ctx, t)
})
treeStorage := changeCreator.CreateNewTreeStorage(t, "0", aclList.Head().Id, isDerived)
objTree, err := objTreeBuilder(treeStorage, aclList)
require.NoError(t, err, "building tree should be without error")

View file

@ -73,7 +73,7 @@ func (m mockKeyStorage) PubKeyFromProto(protoBytes []byte) (crypto.PubKey, error
}
type MockChangeCreator struct {
store anystore.DB
storeCreator func() anystore.DB
}
type testStorage struct {
@ -88,9 +88,9 @@ func (t *testStorage) AddAll(ctx context.Context, changes []StorageChange, heads
return t.Storage.AddAll(ctx, changes, heads, commonSnapshot)
}
func NewMockChangeCreator(store anystore.DB) *MockChangeCreator {
func NewMockChangeCreator(storeCreator func() anystore.DB) *MockChangeCreator {
return &MockChangeCreator{
store: store,
storeCreator: storeCreator,
}
}
@ -164,7 +164,7 @@ func (c *MockChangeCreator) CreateNewTreeStorage(t *testing.T, treeId, aclHeadId
ChangeBuilder: NewChangeBuilder(newMockKeyStorage(), rootChange),
}
}
storage, err := createStorage(context.Background(), root, c.store)
storage, err := createStorage(context.Background(), root, c.storeCreator())
require.NoError(t, err)
return &testStorage{
Storage: storage,

View file

@ -122,6 +122,8 @@ func (tb *treeBuilder) build(opts treeBuilderOpts) (tr *Tree, err error) {
ch.OrderId = storageChange.OrderId
ch.SnapshotCounter = storageChange.SnapshotCounter
changes = append(changes, ch)
// TODO: in case of history tree we should only iterate until we see the order of max head
// that way we can avoid iterating over all changes, though we still need to filter
return true, nil
})
if err != nil {

View file

@ -12,6 +12,9 @@ func (t *Tree) clearPossibleRoots() {
// makeRootAndRemove removes all changes before start and makes start the root
func (t *Tree) makeRootAndRemove(start *Change) {
if start.Id == t.root.Id {
return
}
t.stackBuf = t.stackBuf[:0]
stack := t.stackBuf
for _, prev := range start.PreviousIds {