mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
tests: Remove racey failedDisks behavior in RenameObject tests. (#2138)
Additionally also initialize namespace lock only once per test run, there is no reason to initialize it multiple times to avoid races. Fixes #2137
This commit is contained in:
parent
5ec7734d88
commit
4c21d6d09d
@ -20,9 +20,6 @@ import "testing"
|
||||
|
||||
// Tests functionality provided by namespace lock.
|
||||
func TestNamespaceLockTest(t *testing.T) {
|
||||
// Initialize name space lock.
|
||||
initNSLock()
|
||||
|
||||
// List of test cases.
|
||||
testCases := []struct {
|
||||
lk func(s1, s2 string)
|
||||
|
@ -40,6 +40,12 @@ import (
|
||||
router "github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Tests should initNSLock only once.
|
||||
func init() {
|
||||
// Initialize name space lock.
|
||||
initNSLock()
|
||||
}
|
||||
|
||||
// The Argument to TestServer should satidy the interface.
|
||||
// Golang Testing.T and Testing.B, and gocheck.C satisfy the interface.
|
||||
// This makes it easy to run the TestServer from any of the tests.
|
||||
@ -554,9 +560,6 @@ func getXLObjectLayer() (ObjectLayer, []string, error) {
|
||||
erasureDisks = append(erasureDisks, path)
|
||||
}
|
||||
|
||||
// Initialize name space lock.
|
||||
initNSLock()
|
||||
|
||||
objLayer, err := newXLObjects(erasureDisks)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -572,9 +575,6 @@ func getSingleNodeObjectLayer() (ObjectLayer, string, error) {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
// Initialize name space lock.
|
||||
initNSLock()
|
||||
|
||||
// Create the obj.
|
||||
objLayer, err := newFSObjects(fsDir)
|
||||
if err != nil {
|
||||
|
@ -23,60 +23,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func failDisks(xl xlObjects, n int) (removedDisks []StorageAPI) {
|
||||
removedDisks = make([]StorageAPI, 8)
|
||||
copy(removedDisks, xl.storageDisks[8:])
|
||||
xl.storageDisks = xl.storageDisks[:8]
|
||||
for i := 0; i < n; i++ {
|
||||
xl.storageDisks = append(xl.storageDisks, nil)
|
||||
}
|
||||
return removedDisks
|
||||
}
|
||||
|
||||
func TestRenameObjectWriteQuorum(t *testing.T) {
|
||||
var objLayer ObjectLayer
|
||||
var disks []string
|
||||
var err error
|
||||
|
||||
objLayer, disks, err = getXLObjectLayer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// cleaning up of temporary test directories
|
||||
defer removeRoots(disks)
|
||||
|
||||
err = objLayer.MakeBucket("bucket1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := bytes.NewReader([]byte("hello"))
|
||||
_, err = objLayer.PutObject("bucket1", "obj1", 5, data, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Simulate failure of disks
|
||||
xl := objLayer.(xlObjects)
|
||||
removedDisks := failDisks(xl, 8)
|
||||
if err = xl.renameObject("bucket1", "obj1", ".minio", "obj1"); err != errXLWriteQuorum {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Restoring the failed disks back
|
||||
xl.storageDisks = append(xl.storageDisks[:4], removedDisks...)
|
||||
|
||||
// With all disks back online, renameObject should succeed.
|
||||
if err = xl.renameObject("bucket1", "obj1", ".minio", "obj1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// ... so should renaming back (succeed).
|
||||
if err = xl.renameObject(".minio", "obj1", "bucket1", "obj1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatPutObjectPart(t *testing.T) {
|
||||
var objLayer ObjectLayer
|
||||
var disks []string
|
||||
|
Loading…
Reference in New Issue
Block a user