MCPcopy
hub / github.com/syncthing/syncthing / TestSkipBlockIndexOnUpdate

Function TestSkipBlockIndexOnUpdate

internal/db/sqlite/db_local_test.go:297–345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

295}
296
297func TestSkipBlockIndexOnUpdate(t *testing.T) {
298 t.Parallel()
299
300 sdb, err := Open(t.TempDir())
301 if err != nil {
302 t.Fatal(err)
303 }
304 t.Cleanup(func() { sdb.Close() })
305
306 // Insert a file with SkipBlockIndex
307 file := genFile("a", 3, 0)
308 if err := sdb.Update(folderID, protocol.LocalDeviceID, []protocol.FileInfo{file}, db.WithSkipBlockIndex()); err != nil {
309 t.Fatal(err)
310 }
311
312 // Blocks should not be indexed
313 hits, err := itererr.Collect(sdb.AllLocalBlocksWithHash(folderID, file.Blocks[0].Hash))
314 if err != nil {
315 t.Fatal(err)
316 }
317 if len(hits) != 0 {
318 t.Fatal("expected no block hits with SkipBlockIndex")
319 }
320
321 // The blocklist should still be stored (file info is retrievable with blocks)
322 fi, ok, err := sdb.GetDeviceFile(folderID, protocol.LocalDeviceID, "a")
323 if err != nil {
324 t.Fatal(err)
325 }
326 if !ok {
327 t.Fatal("file not found")
328 }
329 if len(fi.Blocks) != 3 {
330 t.Fatalf("expected 3 blocks in file info, got %d", len(fi.Blocks))
331 }
332
333 // Populate should fill in the blocks
334 if err := sdb.PopulateBlockIndex(folderID); err != nil {
335 t.Fatal(err)
336 }
337
338 hits, err = itererr.Collect(sdb.AllLocalBlocksWithHash(folderID, file.Blocks[0].Hash))
339 if err != nil {
340 t.Fatal(err)
341 }
342 if len(hits) != 1 {
343 t.Fatal("expected one hit after populate")
344 }
345}
346
347func TestRemoteSequence(t *testing.T) {
348 t.Parallel()

Callers

nothing calls this directly

Calls 10

WithSkipBlockIndexFunction · 0.92
CollectFunction · 0.92
OpenFunction · 0.85
genFileFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
UpdateMethod · 0.65
GetDeviceFileMethod · 0.65
PopulateBlockIndexMethod · 0.65

Tested by

no test coverage detected