| 
									
										
										
										
											2016-11-02 11:04:32 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2014, 2015, 2016, 2017 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-11-02 11:04:32 +08: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-16 04:27:16 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2016-11-02 11:04:32 +08:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | // Tests cleanup multipart uploads for erasure coded backend.
 | 
					
						
							| 
									
										
										
										
											2018-03-16 04:55:23 +08:00
										 |  |  | func TestXLCleanupStaleMultipartUploads(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 	// Create an instance of xl backend
 | 
					
						
							| 
									
										
										
										
											2017-12-29 01:32:48 +08:00
										 |  |  | 	obj, fsDirs, err := prepareXL16() | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// Defer cleanup of backend directories
 | 
					
						
							|  |  |  | 	defer removeRoots(fsDirs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	xl := obj.(*xlObjects) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Close the go-routine, we are going to
 | 
					
						
							|  |  |  | 	// manually start it and test in this test case.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	GlobalServiceDoneCh <- struct{}{} | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bucketName := "bucket" | 
					
						
							|  |  |  | 	objectName := "object" | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | 	var opts ObjectOptions | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 04:27:16 +08:00
										 |  |  | 	obj.MakeBucketWithLocation(context.Background(), bucketName, "") | 
					
						
							| 
									
										
										
										
											2019-02-09 13:31:06 +08:00
										 |  |  | 	uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, opts) | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal("Unexpected err: ", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	go xl.cleanupStaleMultipartUploads(context.Background(), 20*time.Millisecond, 0, GlobalServiceDoneCh) | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Wait for 40ms such that - we have given enough time for
 | 
					
						
							|  |  |  | 	// cleanup routine to kick in.
 | 
					
						
							|  |  |  | 	time.Sleep(40 * time.Millisecond) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Close the routine we do not need it anymore.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	GlobalServiceDoneCh <- struct{}{} | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Check if upload id was already purged.
 | 
					
						
							| 
									
										
										
										
											2018-03-16 04:27:16 +08:00
										 |  |  | 	if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { | 
					
						
							| 
									
										
										
										
											2017-12-01 10:11:42 +08:00
										 |  |  | 		if _, ok := err.(InvalidUploadID); !ok { | 
					
						
							|  |  |  | 			t.Fatal("Unexpected err: ", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |