From ca69e54cb6e4cff32b39cef6c7231c6d7ee6fca6 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 12 May 2022 23:24:58 +0100 Subject: [PATCH] tests: Fix sporadic failure of TestXLStorageDeleteFile (#14911) The test expects from DeleteFile to return errDiskNotFound when the disk is not available. It calls os.RemoveAll() to remove one disk after XL storage initialization. However, this latter contains some goroutines which can race with os.RemoveAll() and then the test fails sporadically with returning random errors. The commit will tweak the initialization routine of the XL storage to only run deletion of temporary and metacache data in the background, so TestXLStorageDeleteFile won't fail anymore. --- cmd/prepare-storage.go | 5 ++--- cmd/xl-storage.go | 2 +- cmd/xl-storage_test.go | 18 +++++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 6d4b2d6fb..fd3cbcad3 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -70,7 +70,7 @@ var printEndpointError = func() func(Endpoint, error, bool) { }() // Cleans up tmp directory of the local disk. -func formatErasureCleanupTmp(diskPath string) { +func bgFormatErasureCleanupTmp(diskPath string) { // Need to move temporary objects left behind from previous run of minio // server to a unique directory under `minioMetaTmpBucket-old` to clean // up `minioMetaTmpBucket` for the current run. @@ -98,9 +98,8 @@ func formatErasureCleanupTmp(diskPath string) { } go removeAll(tmpOld) - // Renames and schedules for purging all bucket metacache. - renameAllBucketMetacache(diskPath) + go renameAllBucketMetacache(diskPath) } // Following error message is added to fix a regression in release diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index 9fb4d2509..3283d7e46 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -244,7 +244,7 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) { diskIndex: -1, } - go formatErasureCleanupTmp(s.diskPath) // cleanup any old data. + bgFormatErasureCleanupTmp(s.diskPath) // cleanup any old data. formatData, formatFi, err := formatErasureMigrate(s.diskPath) if err != nil && !errors.Is(err, os.ErrNotExist) { diff --git a/cmd/xl-storage_test.go b/cmd/xl-storage_test.go index ca42a2491..0c58ca3d0 100644 --- a/cmd/xl-storage_test.go +++ b/cmd/xl-storage_test.go @@ -959,13 +959,6 @@ func TestXLStorageDeleteFile(t *testing.T) { } defer os.RemoveAll(path) - // create xlStorage test setup - xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup() - if err != nil { - t.Fatalf("Unable to create xlStorage test setup, %s", err) - } - // removing the disk, used to recreate disk not found error. - os.RemoveAll(diskPath) // Setup test environment. if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil { t.Fatalf("Unable to create volume, %s", err) @@ -1066,6 +1059,17 @@ func TestXLStorageDeleteFile(t *testing.T) { } } + // create xlStorage test setup + xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup() + if err != nil { + t.Fatalf("Unable to create xlStorage test setup, %s", err) + } + // removing the disk, used to recreate disk not found error. + err = os.RemoveAll(diskPath) + if err != nil { + t.Fatalf("Unable to remoe xlStorage diskpath, %s", err) + } + // TestXLStorage for delete on an removed disk. // should fail with disk not found. err = xlStorageDeletedStorage.Delete(context.Background(), "del-vol", "my-file", false)