2016-11-01 23:04:32 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2014, 2015, 2016, 2017 MinIO, Inc.
|
2016-11-01 23:04:32 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-15 16:27:16 -04:00
|
|
|
"context"
|
2020-03-18 19:19:29 -04:00
|
|
|
"sync"
|
2016-11-01 23:04:32 -04:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-11-30 21:11:42 -05:00
|
|
|
// Tests cleanup multipart uploads for erasure coded backend.
|
2018-03-15 16:55:23 -04:00
|
|
|
func TestXLCleanupStaleMultipartUploads(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2017-11-30 21:11:42 -05:00
|
|
|
// Create an instance of xl backend
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2017-11-30 21:11:42 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Defer cleanup of backend directories
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
2019-11-19 20:42:27 -05:00
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2017-11-30 21:11:42 -05:00
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
2018-09-10 12:42:43 -04:00
|
|
|
var opts ObjectOptions
|
2017-11-30 21:11:42 -05:00
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
obj.MakeBucketWithLocation(ctx, bucketName, "")
|
2020-04-09 12:30:02 -04:00
|
|
|
uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, opts)
|
2017-11-30 21:11:42 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
2020-03-18 19:19:29 -04:00
|
|
|
var cleanupWg sync.WaitGroup
|
|
|
|
cleanupWg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer cleanupWg.Done()
|
2020-04-09 12:30:02 -04:00
|
|
|
xl.cleanupStaleMultipartUploads(GlobalContext, time.Millisecond, 0, ctx.Done())
|
2020-03-18 19:19:29 -04:00
|
|
|
}()
|
2017-11-30 21:11:42 -05:00
|
|
|
|
2020-03-18 19:19:29 -04:00
|
|
|
// Wait for 100ms such that - we have given enough time for cleanup routine to kick in.
|
|
|
|
// Flaky on slow systems :/
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2017-11-30 21:11:42 -05:00
|
|
|
|
2020-03-18 19:19:29 -04:00
|
|
|
// Exit cleanup..
|
|
|
|
cancel()
|
|
|
|
cleanupWg.Wait()
|
2017-11-30 21:11:42 -05:00
|
|
|
|
|
|
|
// Check if upload id was already purged.
|
2020-04-14 20:52:38 -04:00
|
|
|
if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil {
|
2017-11-30 21:11:42 -05:00
|
|
|
if _, ok := err.(InvalidUploadID); !ok {
|
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
2020-03-18 19:19:29 -04:00
|
|
|
} else {
|
|
|
|
t.Error("Item was not cleaned up.")
|
2017-11-30 21:11:42 -05:00
|
|
|
}
|
|
|
|
}
|