Test the cache reading a file that is updated externally See: https://github.com/rclone/rclone/issues/6053
(t *testing.T)
| 719 | // |
| 720 | // See: https://github.com/rclone/rclone/issues/6053 |
| 721 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…