MCPcopy
hub / github.com/rclone/rclone / TestRWCacheUpdate

Function TestRWCacheUpdate

vfs/read_write_test.go:721–761  ·  view source on GitHub ↗

Test the cache reading a file that is updated externally See: https://github.com/rclone/rclone/issues/6053

(t *testing.T)

Source from the content-addressed store, hash-verified

719//
720// See: https://github.com/rclone/rclone/issues/6053
721func TestRWCacheUpdate(t *testing.T) {
722 opt := vfscommon.Opt
723 opt.CacheMode = vfscommon.CacheModeFull
724 opt.WriteBack = writeBackDelay
725 opt.DirCacheTime = fs.Duration(100 * time.Millisecond)
726 opt.HandleCaching = 0
727 r, vfs := newTestVFSOpt(t, &opt)
728
729 if r.Fremote.Precision() == fs.ModTimeNotSupported {
730 t.Skip("skip as modtime not supported")
731 }
732
733 const filename = "TestRWCacheUpdate"
734
735 modTime := time.Now().Add(-time.Hour)
736 for i := range 10 {
737 modTime = modTime.Add(time.Minute)
738 // Refresh test file
739 contents := fmt.Sprintf("TestRWCacheUpdate%03d", i)
740 // Increase the size for second half of test
741 for j := 5; j < i; j++ {
742 contents += "*"
743 }
744 file1 := r.WriteObject(context.Background(), filename, contents, modTime)
745 r.CheckRemoteItems(t, file1)
746
747 // Wait for directory cache to expire
748 time.Sleep(time.Duration(2 * opt.DirCacheTime))
749
750 // Check the file is OK via the VFS
751 data, err := vfs.ReadFile(filename)
752 require.NoError(t, err)
753 require.Equal(t, contents, string(data))
754
755 // Check Stat
756 fi, err := vfs.Stat(filename)
757 require.NoError(t, err)
758 assert.Equal(t, int64(len(contents)), fi.Size())
759 fstest.AssertTimeEqualWithPrecision(t, filename, modTime, fi.ModTime(), r.Fremote.Precision())
760 }
761}

Callers

nothing calls this directly

Calls 12

DurationTypeAlias · 0.92
newTestVFSOptFunction · 0.85
WriteObjectMethod · 0.80
CheckRemoteItemsMethod · 0.80
PrecisionMethod · 0.65
AddMethod · 0.65
ReadFileMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.65
ModTimeMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…