MCPcopy Index your code
hub / github.com/syncthing/syncthing / TestBlocklistGarbageCollection

Function TestBlocklistGarbageCollection

internal/db/sqlite/db_test.go:990–1067  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

988}
989
990func TestBlocklistGarbageCollection(t *testing.T) {
991 t.Parallel()
992
993 sdb, err := Open(t.TempDir())
994 if err != nil {
995 t.Fatal(err)
996 }
997 t.Cleanup(func() {
998 if err := sdb.Close(); err != nil {
999 t.Fatal(err)
1000 }
1001 })
1002 svc := sdb.Service(time.Hour).(*Service)
1003
1004 // Add three files
1005
1006 files := []protocol.FileInfo{
1007 genFile("test1", 1, 1),
1008 genFile("test2", 2, 2),
1009 genFile("test3", 3, 3),
1010 }
1011
1012 if err := sdb.Update(folderID, protocol.LocalDeviceID, files); err != nil {
1013 t.Fatal(err)
1014 }
1015
1016 // There should exist three blockslists and six blocks
1017
1018 fdb, err := sdb.getFolderDB(folderID, false)
1019 if err != nil {
1020 t.Fatal(err)
1021 }
1022
1023 var count int
1024 if err := fdb.sql.Get(&count, `SELECT count(*) FROM blocklists`); err != nil {
1025 t.Fatal(err)
1026 }
1027 if count != 3 {
1028 t.Log(count)
1029 t.Fatal("expected 3 blocklists")
1030 }
1031 if err := fdb.sql.Get(&count, `SELECT count(*) FROM blocks`); err != nil {
1032 t.Fatal(err)
1033 }
1034 if count != 6 {
1035 t.Log(count)
1036 t.Fatal("expected 6 blocks")
1037 }
1038
1039 // Mark test3 as deleted, it's blocks and blocklist are now eligible for collection
1040 files = files[2:]
1041 files[0].SetDeleted(42)
1042 if err := sdb.Update(folderID, protocol.LocalDeviceID, files); err != nil {
1043 t.Fatal(err)
1044 }
1045
1046 // Run garbage collection
1047 if err := svc.periodic(context.Background()); err != nil {

Callers

nothing calls this directly

Calls 12

OpenFunction · 0.85
genFileFunction · 0.85
FatalMethod · 0.80
getFolderDBMethod · 0.80
SetDeletedMethod · 0.80
periodicMethod · 0.80
CloseMethod · 0.65
ServiceMethod · 0.65
UpdateMethod · 0.65
GetMethod · 0.65
LogMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected