Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cleanup function to remove all the objects from a bucket after tests #835

Merged
merged 2 commits into from Oct 5, 2017

Conversation

nitisht
Copy link
Contributor

@nitisht nitisht commented Sep 30, 2017

Fixes : minio/mint#165
and improves logging by adding args in few test cases.

// Remove the newly created bucket.
if err = c.RemoveBucket(bucketName + ".withperiod"); err != nil {
failureLog(function, args, startTime, "", "Remove bucket failed", err).Fatal()
// cleanup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more descriptive comment rather than place holder like cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Updated the comments

@@ -1613,7 +1608,7 @@ func testPutObjectWithContext() {
args := map[string]interface{}{
"bucketName": "",
"objectName": "",
"opts": "minio.PutObjectOptions{ContentType:objectContentType}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change? shouldn't we add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was a typo, fixed.

buckets, err := c.ListBuckets()

for _, bucket := range buckets {
for obj := range c.ListObjects(bucket.Name, "", true, doneCh) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put each ListObjects() on a go-routine since they are independent buckets and clean them up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nitisht nitisht force-pushed the cleanup-tests branch 4 times, most recently from 3059a7c to 5229da4 Compare October 1, 2017 13:24
}
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function will end up cleaning more than the buckets created by this minio-go functional test. Shouldn't you be checking whether the bucket-prefix matches minio-go and then delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it will delete everything on the server. Let me add the bucket prefix check

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)

buckets, err = c.ListBuckets()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return on error right here..

err = c.RemoveObject(bucketName, object.Key)
}
} else {
err = object.Err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not set the err from outside scope in a go-routine, collect all errors.. in a errs []error and then store them based on the buckets index. like this

for i, bucket := range buckets {
     go func(i int, bucketName string) {
           ....
           errs[i] = err
     }(i, bucket)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also since there is no wait group, this won't delete all buckets all the time. Since the program might exit if this function returns after all go-routines have spawned.

Use wait group to limit yourself and use wg.Wait() to wait for cleaning up of all buckets. Once done loop through

for _, err := range errs {
        if err != nil {
             return err 
        }
}

@nitisht nitisht force-pushed the cleanup-tests branch 11 times, most recently from e486703 to 057573d Compare October 4, 2017 14:09
@nitisht nitisht changed the title Add cleanup function to remove all the objects and buckets after tests Add cleanup function to remove all the objects from a bucket after tests Oct 4, 2017
@nitisht
Copy link
Contributor Author

nitisht commented Oct 4, 2017

Updated the PR with a simpler approach to cleanup, since previous approach failed if there are multiple instances of minio-go tests running in parallel against a single server, cleanup deleted buckets belonging to other test instances as well - for example when travis runs multiple minio-go tests against play server.

Please take a look @harshavardhana @poornas

return err
}
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there are incomplete upload parts? that would need cleanup as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain a bit more @poornas

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there are incomplete uploads to a bucket, RemoveBucket would fail. For tests using large uploads, shouldn't the cleanup also remove incomplete uploads if any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @poornas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveBucket works fine on all gateways even with incomplete uploads, that is the S3 behavior. But it is a good change since it will cater for B2 gateway backend as well. Which requires explicit removal of incomplete uploads.

for objPartInfo := range c.ListIncompleteUploads(bucketName, "", true, doneCh) {
if objPartInfo.Err != nil {
return objPartInfo.Err
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

for objCh := range c.ListObjectsV2(bucketName, "", true, doneCh) {
if objCh.Err != nil {
return objCh.Err
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

@harshavardhana
Copy link
Member

Partially fixes : minio/mint#165
and improves logging by adding args in few test cases.

Is this true that it partially fixes? @nitisht

@nitisht
Copy link
Contributor Author

nitisht commented Oct 5, 2017

Is this true that it partially fixes?

Let me change it to fixes, initially there were stale buckets left by minio-js as well

[2017-09-29 17:11:02 PDT] 100KiB 41b17354-ff91-478d-9a46-353830d48767/datafile-100-kB
[2017-09-29 17:11:02 PDT] 100KiB 41b17354-ff91-478d-9a46-353830d48767/datafile-100-kB.buffer

but that is not seen anymore.

@deekoder deekoder merged commit adf661d into minio:master Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants