From 20a15567b80fda89079ff855ab57e450ab3b1256 Mon Sep 17 00:00:00 2001 From: poornas Date: Wed, 10 Jul 2019 15:41:11 -0700 Subject: [PATCH] Fix atime support check for disk cache (#7891) - add a sleep between Stat operations to accurately detect atime --- cmd/disk-cache.go | 5 ++++- cmd/disk-cache_test.go | 17 +++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index ef76560e9..c1ab3b398 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -945,7 +945,10 @@ func checkAtimeSupport(dir string) (err error) { if err != nil { return } - if _, err = io.Copy(ioutil.Discard, file); err != io.EOF { + // add a sleep to ensure atime change is detected + time.Sleep(10 * time.Millisecond) + + if _, err = io.Copy(ioutil.Discard, file); err != nil { return } diff --git a/cmd/disk-cache_test.go b/cmd/disk-cache_test.go index 0313390d8..ffbdc9ba9 100644 --- a/cmd/disk-cache_test.go +++ b/cmd/disk-cache_test.go @@ -124,17 +124,10 @@ func TestGetCacheFSMaxUse(t *testing.T) { // test wildcard patterns for excluding entries from cache func TestCacheExclusion(t *testing.T) { - fsDirs, err := getRandomDisks(1) - if err != nil { - t.Fatal(err) + cobjects := &cacheObjects{ + cache: nil, } - cconfig := CacheConfig{Expiry: 30, Drives: fsDirs} - cobjects, err := newServerCacheObjects(cconfig) - if err != nil { - t.Fatal(err) - } - cobj := cobjects.(*cacheObjects) - GlobalServiceDoneCh <- struct{}{} + testCases := []struct { bucketName string objectName string @@ -155,8 +148,8 @@ func TestCacheExclusion(t *testing.T) { } for i, testCase := range testCases { - cobj.exclude = []string{testCase.excludePattern} - if cobj.isCacheExclude(testCase.bucketName, testCase.objectName) != testCase.expectedResult { + cobjects.exclude = []string{testCase.excludePattern} + if cobjects.isCacheExclude(testCase.bucketName, testCase.objectName) != testCase.expectedResult { t.Fatal("Cache exclusion test failed for case ", i) } }