2016-11-02 04:04:32 +01:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2014, 2015, 2016, 2017 MinIO, Inc.
|
2016-11-02 04:04:32 +01: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 21:27:16 +01:00
|
|
|
"context"
|
2020-03-19 00:19:29 +01:00
|
|
|
"sync"
|
2016-11-02 04:04:32 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-12-01 03:11:42 +01:00
|
|
|
// Tests cleanup multipart uploads for erasure coded backend.
|
2018-03-15 21:55:23 +01:00
|
|
|
func TestXLCleanupStaleMultipartUploads(t *testing.T) {
|
2020-04-15 02:52:38 +02:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2017-12-01 03:11:42 +01:00
|
|
|
// Create an instance of xl backend
|
2020-04-15 02:52:38 +02:00
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2017-12-01 03:11:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Defer cleanup of backend directories
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
2019-11-20 02:42:27 +01:00
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2017-12-01 03:11:42 +01:00
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
2018-09-10 18:42:43 +02:00
|
|
|
var opts ObjectOptions
|
2017-12-01 03:11:42 +01:00
|
|
|
|
2020-04-15 02:52:38 +02:00
|
|
|
obj.MakeBucketWithLocation(ctx, bucketName, "")
|
2020-04-09 18:30:02 +02:00
|
|
|
uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, opts)
|
2017-12-01 03:11:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
2020-03-19 00:19:29 +01:00
|
|
|
var cleanupWg sync.WaitGroup
|
|
|
|
cleanupWg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer cleanupWg.Done()
|
2020-04-09 18:30:02 +02:00
|
|
|
xl.cleanupStaleMultipartUploads(GlobalContext, time.Millisecond, 0, ctx.Done())
|
2020-03-19 00:19:29 +01:00
|
|
|
}()
|
2017-12-01 03:11:42 +01:00
|
|
|
|
2020-03-19 00:19:29 +01: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-12-01 03:11:42 +01:00
|
|
|
|
2020-03-19 00:19:29 +01:00
|
|
|
// Exit cleanup..
|
|
|
|
cancel()
|
|
|
|
cleanupWg.Wait()
|
2017-12-01 03:11:42 +01:00
|
|
|
|
|
|
|
// Check if upload id was already purged.
|
2020-04-15 02:52:38 +02:00
|
|
|
if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil {
|
2017-12-01 03:11:42 +01:00
|
|
|
if _, ok := err.(InvalidUploadID); !ok {
|
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
2020-03-19 00:19:29 +01:00
|
|
|
} else {
|
|
|
|
t.Error("Item was not cleaned up.")
|
2017-12-01 03:11:42 +01:00
|
|
|
}
|
|
|
|
}
|