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
master
Harshavardhana 9 years ago committed by GitHub
parent 5ec7734d88
commit 4c21d6d09d
  1. 3
      namespace-lock_test.go
  2. 12
      test-utils_test.go
  3. 54
      xl-v1-object_test.go

@ -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…
Cancel
Save