lib/ignore, lib/model: Use an interface to detect file changes, improving tests
This solves the erratic test failures on model.TestIgnores by ensuring that the ignore patterns are reloaded even in the face of unchanged timestamps. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4208
This commit is contained in:
committed by
Audrius Butkevicius
parent
2a38d2a3d2
commit
68c1a0b9b4
@@ -12,6 +12,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
fc := new(fakeClock)
|
||||
oldClock := clock
|
||||
clock = fc
|
||||
defer func() {
|
||||
clock = oldClock
|
||||
}()
|
||||
|
||||
c := newCache(nil)
|
||||
|
||||
res, ok := c.get("nonexistent")
|
||||
@@ -52,11 +59,11 @@ func TestCache(t *testing.T) {
|
||||
|
||||
// Sleep and access, to get some data for clean
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
*fc += 500 // milliseconds
|
||||
|
||||
c.get("true")
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
*fc += 100 // milliseconds
|
||||
|
||||
// "false" was accessed ~600 ms ago, "true" was accessed ~100 ms ago.
|
||||
// This should clean out "false" but not "true"
|
||||
@@ -75,3 +82,11 @@ func TestCache(t *testing.T) {
|
||||
t.Errorf("item should have been cleaned")
|
||||
}
|
||||
}
|
||||
|
||||
type fakeClock int64 // milliseconds
|
||||
|
||||
func (f *fakeClock) Now() time.Time {
|
||||
t := time.Unix(int64(*f)/1000, (int64(*f)%1000)*int64(time.Millisecond))
|
||||
*f++
|
||||
return t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user