lib/model: Don't set ignore bit when it's already set
This adds a metric for "committed items" to the database instance that I use in the test code, and a couple of tests that ensure that scans that don't change anything also don't commit anything. There was a case in the scanner where we set the invalid bit on files that are ignored, even though they were already ignored and had the invalid bit set. I had assumed this would result in an extra database commit, but it was in fact filtered out by the Set... Anyway, I think we can save some work on not pushing that change to the Set at all. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3298
This commit is contained in:
committed by
Audrius Butkevicius
parent
bb5b1f8f01
commit
b779e22205
@@ -624,6 +624,39 @@ func TestLongPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitted(t *testing.T) {
|
||||
// Verify that the Committed counter increases when we change things and
|
||||
// doesn't increase when we don't.
|
||||
|
||||
ldb := db.OpenMemory()
|
||||
|
||||
s := db.NewFileSet("test", ldb)
|
||||
|
||||
local := []protocol.FileInfo{
|
||||
{Name: string("file"), Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
||||
}
|
||||
|
||||
// Adding a file should increase the counter
|
||||
|
||||
c0 := ldb.Committed()
|
||||
|
||||
s.Replace(protocol.LocalDeviceID, local)
|
||||
|
||||
c1 := ldb.Committed()
|
||||
if c1 <= c0 {
|
||||
t.Errorf("committed data didn't increase; %d <= %d", c1, c0)
|
||||
}
|
||||
|
||||
// Updating with something identical should not do anything
|
||||
|
||||
s.Update(protocol.LocalDeviceID, local)
|
||||
|
||||
c2 := ldb.Committed()
|
||||
if c2 > c1 {
|
||||
t.Errorf("replace with same contents should do nothing but %d > %d", c2, c1)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUpdateOneFile(b *testing.B) {
|
||||
local0 := fileList{
|
||||
protocol.FileInfo{Name: "a", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(1)},
|
||||
|
||||
Reference in New Issue
Block a user