@@ -16,7 +16,6 @@ import (
16
16
"github.com/anyproto/any-sync/commonspace/settings"
17
17
"github.com/anyproto/any-sync/commonspace/settings/settingsstate"
18
18
"github.com/anyproto/any-sync/commonspace/spacestorage"
19
- "github.com/anyproto/any-sync/commonspace/spacesyncproto"
20
19
"github.com/anyproto/any-sync/commonspace/syncstatus"
21
20
"github.com/anyproto/any-sync/util/crypto"
22
21
)
@@ -127,95 +126,6 @@ func createTree(t *testing.T, ctx context.Context, spc Space, acc *accountdata.A
127
126
return tr .Id ()
128
127
}
129
128
130
- func TestSpaceDeleteIdsIncorrectSnapshot (t * testing.T ) {
131
- fx := newFixture (t )
132
- acc := fx .account .Account ()
133
- rk := crypto .NewAES ()
134
- privKey , _ , _ := crypto .GenerateRandomEd25519KeyPair ()
135
- ctx := context .Background ()
136
- totalObjs := 1500
137
- partialObjs := 300
138
-
139
- // creating space
140
- sp , err := fx .spaceService .CreateSpace (ctx , SpaceCreatePayload {
141
- SigningKey : acc .SignKey ,
142
- SpaceType : "type" ,
143
- ReadKey : rk ,
144
- MetadataKey : privKey ,
145
- ReplicationKey : 10 ,
146
- MasterKey : acc .PeerKey ,
147
- })
148
- require .NoError (t , err )
149
- require .NotNil (t , sp )
150
-
151
- // initializing space
152
- spc , err := fx .spaceService .NewSpace (ctx , sp , Deps {TreeSyncer : mockTreeSyncer {}, SyncStatus : syncstatus .NewNoOpSyncStatus ()})
153
- require .NoError (t , err )
154
- require .NotNil (t , spc )
155
- // adding space to tree manager
156
- fx .treeManager .space = spc
157
- err = spc .Init (ctx )
158
- close (fx .treeManager .waitLoad )
159
- require .NoError (t , err )
160
-
161
- settingsObject := spc .(* space ).app .MustComponent (settings .CName ).(settings.Settings ).SettingsObject ()
162
- var ids []string
163
- for i := 0 ; i < totalObjs ; i ++ {
164
- id := createTree (t , ctx , spc , acc )
165
- ids = append (ids , id )
166
- }
167
- // copying storage, so we will have all the trees locally
168
- inmemory := spc .Storage ().(* spacestorage.InMemorySpaceStorage )
169
- storageCopy := inmemory .CopyStorage ()
170
- treesCopy := inmemory .AllTrees ()
171
-
172
- // deleting trees
173
- for _ , id := range ids {
174
- err = spc .DeleteTree (ctx , id )
175
- require .NoError (t , err )
176
- }
177
- mapIds := map [string ]struct {}{}
178
- for _ , id := range ids [:partialObjs ] {
179
- mapIds [id ] = struct {}{}
180
- }
181
- // adding snapshot that breaks the state
182
- err = addIncorrectSnapshot (settingsObject , acc , mapIds , ids [partialObjs ])
183
- require .NoError (t , err )
184
- // copying the contents of the settings tree
185
- treesCopy [settingsObject .Id ()] = settingsObject .Storage ()
186
- storageCopy .SetTrees (treesCopy )
187
- spc .Close ()
188
- time .Sleep (100 * time .Millisecond )
189
- // now we replace the storage, so the trees are back, but the settings object says that they are deleted
190
- fx .storageProvider .(* spacestorage.InMemorySpaceStorageProvider ).SetStorage (storageCopy )
191
-
192
- spc , err = fx .spaceService .NewSpace (ctx , sp , Deps {TreeSyncer : mockTreeSyncer {}, SyncStatus : syncstatus .NewNoOpSyncStatus ()})
193
- require .NoError (t , err )
194
- require .NotNil (t , spc )
195
- fx .treeManager .waitLoad = make (chan struct {})
196
- fx .treeManager .space = spc
197
- fx .treeManager .deletedIds = nil
198
- fx .treeManager .wait = true
199
- err = spc .Init (ctx )
200
- require .NoError (t , err )
201
- close (fx .treeManager .waitLoad )
202
-
203
- // waiting until everything is deleted
204
- time .Sleep (6 * time .Second )
205
- require .Equal (t , len (ids ), len (fx .treeManager .deletedIds ))
206
-
207
- // checking that new snapshot will contain all the changes
208
- settingsObject = spc .(* space ).app .MustComponent (settings .CName ).(settings.Settings ).SettingsObject ()
209
- settings .DoSnapshot = func (treeLen int ) bool {
210
- return true
211
- }
212
- id := createTree (t , ctx , spc , acc )
213
- err = spc .DeleteTree (ctx , id )
214
- require .NoError (t , err )
215
- delIds := settingsObject .Root ().Model .(* spacesyncproto.SettingsData ).Snapshot .DeletedIds
216
- require .Equal (t , totalObjs + 1 , len (delIds ))
217
- }
218
-
219
129
func TestSpaceDeleteIdsMarkDeleted (t * testing.T ) {
220
130
fx := newFixture (t )
221
131
acc := fx .account .Account ()
0 commit comments