(t *testing.T)
| 988 | } |
| 989 | |
| 990 | func 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 { |
nothing calls this directly
no test coverage detected