From 48a2e3844df82beec9254ae03329844aed7be115 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 9 Dec 2016 15:39:29 +0000 Subject: [PATCH] Add optional interface DirCacheFlush for making the tests more reliable This is defined for the users of dircache drive, onedrive, and acd. This helps fix the DirMove tests on acd. --- amazonclouddrive/amazonclouddrive.go | 14 ++++++++++---- drive/drive.go | 23 +++++++++++++++-------- fs/fs.go | 7 +++++++ fstest/fstest.go | 4 ++++ onedrive/onedrive.go | 11 +++++++++-- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/amazonclouddrive/amazonclouddrive.go b/amazonclouddrive/amazonclouddrive.go index 5190aa3dc..770bee3f4 100644 --- a/amazonclouddrive/amazonclouddrive.go +++ b/amazonclouddrive/amazonclouddrive.go @@ -636,6 +636,11 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) { } fs.Debug(src, "Attempting to move to %q", remote) return srcObj.move(remote, false) + +// DirCacheFlush resets the directory cache - used in testing as an +// optional interface +func (f *Fs) DirCacheFlush() { + f.dirCache.ResetRoot() } // DirMove moves src directory to this remote using server side move @@ -1122,8 +1127,9 @@ var ( _ fs.Fs = (*Fs)(nil) _ fs.Purger = (*Fs)(nil) // _ fs.Copier = (*Fs)(nil) - _ fs.Mover = (*Fs)(nil) - _ fs.DirMover = (*Fs)(nil) - _ fs.Object = (*Object)(nil) - _ fs.MimeTyper = &Object{} + _ fs.Mover = (*Fs)(nil) + _ fs.DirMover = (*Fs)(nil) + _ fs.DirCacheFlusher = (*Fs)(nil) + _ fs.Object = (*Object)(nil) + _ fs.MimeTyper = &Object{} ) diff --git a/drive/drive.go b/drive/drive.go index c362ee6ae..14039a7b1 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -799,6 +799,12 @@ func (f *Fs) DirMove(src fs.Fs) error { return nil } +// DirCacheFlush resets the directory cache - used in testing as an +// optional interface +func (f *Fs) DirCacheFlush() { + f.dirCache.ResetRoot() +} + // Hashes returns the supported hash sets. func (f *Fs) Hashes() fs.HashSet { return fs.HashSet(fs.HashMD5) @@ -1079,12 +1085,13 @@ func (o *Object) MimeType() string { // Check the interfaces are satisfied var ( - _ fs.Fs = (*Fs)(nil) - _ fs.Purger = (*Fs)(nil) - _ fs.Copier = (*Fs)(nil) - _ fs.Mover = (*Fs)(nil) - _ fs.DirMover = (*Fs)(nil) - _ fs.PutUncheckeder = (*Fs)(nil) - _ fs.Object = (*Object)(nil) - _ fs.MimeTyper = &Object{} + _ fs.Fs = (*Fs)(nil) + _ fs.Purger = (*Fs)(nil) + _ fs.Copier = (*Fs)(nil) + _ fs.Mover = (*Fs)(nil) + _ fs.DirMover = (*Fs)(nil) + _ fs.DirCacheFlusher = (*Fs)(nil) + _ fs.PutUncheckeder = (*Fs)(nil) + _ fs.Object = (*Object)(nil) + _ fs.MimeTyper = &Object{} ) diff --git a/fs/fs.go b/fs/fs.go index 592245595..42939fc26 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -275,6 +275,13 @@ type UnWrapper interface { UnWrap() Fs } +// DirCacheFlusher is an optional interface for Fs +type DirCacheFlusher interface { + // DirCacheFlush resets the directory cache - used in testing + // as an optional interface + DirCacheFlush() +} + // PutUncheckeder is an optional interface for Fs type PutUncheckeder interface { // Put in to the remote path with the modTime given of the given size diff --git a/fstest/fstest.go b/fstest/fstest.go index 148e4034b..5503d5828 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -175,6 +175,10 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirs sleep *= 2 t.Logf("Sleeping for %v for list eventual consistency: %d/%d", sleep, i, retries) time.Sleep(sleep) + if do, ok := f.(fs.DirCacheFlusher); ok { + t.Logf("Flushing the directory cache") + do.DirCacheFlush() + } } for _, obj := range objs { require.NotNil(t, obj) diff --git a/onedrive/onedrive.go b/onedrive/onedrive.go index 744b3397e..aa1740fed 100644 --- a/onedrive/onedrive.go +++ b/onedrive/onedrive.go @@ -635,6 +635,12 @@ func (f *Fs) Purge() error { return f.purgeCheck("", false) } +// DirCacheFlush resets the directory cache - used in testing as an +// optional interface +func (f *Fs) DirCacheFlush() { + f.dirCache.ResetRoot() +} + // Hashes returns the supported hash sets. func (f *Fs) Hashes() fs.HashSet { return fs.HashSet(fs.HashSHA1) @@ -960,6 +966,7 @@ var ( _ fs.Copier = (*Fs)(nil) // _ fs.Mover = (*Fs)(nil) // _ fs.DirMover = (*Fs)(nil) - _ fs.Object = (*Object)(nil) - _ fs.MimeTyper = &Object{} + _ fs.DirCacheFlusher = (*Fs)(nil) + _ fs.Object = (*Object)(nil) + _ fs.MimeTyper = &Object{} )