lib/model: Fix minor flakiness in TestModTimeWindow

This commit is contained in:
Jakob Borg 2020-06-16 06:31:55 +02:00
parent 36e6f8b082
commit 5be13f62a2

View File

@ -3389,36 +3389,40 @@ func TestModTimeWindow(t *testing.T) {
m.ScanFolders() m.ScanFolders()
v := protocol.Vector{} // Get current version
v = v.Update(myID.Short())
fi, ok := m.CurrentFolderFile("default", name) fi, ok := m.CurrentFolderFile("default", name)
if !ok { if !ok {
t.Fatal("File missing") t.Fatal("File missing")
} }
if !fi.Version.Equal(v) { v := fi.Version
t.Fatalf("Got version %v, expected %v", fi.Version, v)
} // Update time on disk 1s
err = tfs.Chtimes(name, time.Now(), modTime.Add(time.Second)) err = tfs.Chtimes(name, time.Now(), modTime.Add(time.Second))
must(t, err) must(t, err)
m.ScanFolders() m.ScanFolders()
// No change due to window // No change due to within window
fi, _ = m.CurrentFolderFile("default", name) fi, _ = m.CurrentFolderFile("default", name)
if !fi.Version.Equal(v) { if !fi.Version.Equal(v) {
t.Fatalf("Got version %v, expected %v", fi.Version, v) t.Fatalf("Got version %v, expected %v", fi.Version, v)
} }
// Update to be outside window
err = tfs.Chtimes(name, time.Now(), modTime.Add(2*time.Second)) err = tfs.Chtimes(name, time.Now(), modTime.Add(2*time.Second))
must(t, err) must(t, err)
m.ScanFolders() m.ScanFolders()
v = v.Update(myID.Short()) // Version should have updated
fi, _ = m.CurrentFolderFile("default", name) fi, _ = m.CurrentFolderFile("default", name)
if !fi.Version.Equal(v) { if fi.Version.Compare(v) != protocol.Greater {
t.Fatalf("Got version %v, expected %v", fi.Version, v) t.Fatalf("Got result %v, expected %v", fi.Version.Compare(v), protocol.Greater)
} }
} }