MCPcopy
hub / github.com/syncthing/syncthing / TestModTimeWindow

Function TestModTimeWindow

lib/model/model_test.go:3061–3120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3059}
3060
3061func TestModTimeWindow(t *testing.T) {
3062 w, fcfg := newDefaultCfgWrapper(t)
3063 tfs := modtimeTruncatingFS{
3064 trunc: 0,
3065 Filesystem: fcfg.Filesystem(),
3066 }
3067 // fcfg.RawModTimeWindowS = 2
3068 setFolder(t, w, fcfg)
3069 m := setupModel(t, w)
3070 defer cleanupModelAndRemoveDir(m, tfs.URI())
3071
3072 name := "foo"
3073
3074 fd, err := tfs.Create(name)
3075 must(t, err)
3076 stat, err := fd.Stat()
3077 must(t, err)
3078 modTime := stat.ModTime()
3079 fd.Close()
3080
3081 m.ScanFolders()
3082
3083 // Get current version
3084
3085 fi, ok := m.testCurrentFolderFile("default", name)
3086 if !ok {
3087 t.Fatal("File missing")
3088 }
3089 v := fi.Version
3090
3091 // Change the filesystem to only return modtimes to the closest two
3092 // seconds, like FAT.
3093
3094 tfs.trunc = 2 * time.Second
3095
3096 // Scan again
3097
3098 m.ScanFolders()
3099
3100 // No change due to within window
3101
3102 fi, _ = m.testCurrentFolderFile("default", name)
3103 if !fi.Version.Equal(v) {
3104 t.Fatalf("Got version %v, expected %v", fi.Version, v)
3105 }
3106
3107 // Update to be outside window
3108
3109 err = tfs.Chtimes(name, time.Now(), modTime.Add(2*time.Second))
3110 must(t, err)
3111
3112 m.ScanFolders()
3113
3114 // Version should have updated
3115
3116 fi, _ = m.testCurrentFolderFile("default", name)
3117 if fi.Version.Compare(v) != protocol.Greater {
3118 t.Fatalf("Got result %v, expected %v", fi.Version.Compare(v), protocol.Greater)

Callers

nothing calls this directly

Calls 15

newDefaultCfgWrapperFunction · 0.85
setFolderFunction · 0.85
setupModelFunction · 0.85
cleanupModelAndRemoveDirFunction · 0.85
mustFunction · 0.85
FilesystemMethod · 0.80
testCurrentFolderFileMethod · 0.80
FatalMethod · 0.80
URIMethod · 0.65
CreateMethod · 0.65
StatMethod · 0.65
ModTimeMethod · 0.65

Tested by

no test coverage detected