Avoid shutdown fs multiple times and create a new fs in each loop (#3213)

This commit is contained in:
Anis Elleuch 2016-11-09 19:10:14 +01:00 committed by Harshavardhana
parent daf6f3a5c0
commit ea579f5b69

View file

@ -99,35 +99,38 @@ func TestNewFS(t *testing.T) {
// TestFSShutdown - initialize a new FS object layer then calls Shutdown // TestFSShutdown - initialize a new FS object layer then calls Shutdown
// to check returned results // to check returned results
func TestFSShutdown(t *testing.T) { func TestFSShutdown(t *testing.T) {
// Prepare for tests
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
defer removeAll(disk)
obj := initFSObjects(disk, t)
fs := obj.(fsObjects) // Create and return an fsObject with its path in the disk
fsStorage := fs.storage.(*posix) prepareTest := func() (fsObjects, string) {
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
bucketName := "testbucket" obj := initFSObjects(disk, t)
objectName := "object" fs := obj.(fsObjects)
objectContent := "12345" bucketName := "testbucket"
objectName := "object"
obj.MakeBucket(bucketName) objectContent := "12345"
sha256sum := "" obj.MakeBucket(bucketName)
obj.PutObject(bucketName, objectName, int64(len(objectContent)), bytes.NewReader([]byte(objectContent)), nil, sha256sum) sha256sum := ""
obj.PutObject(bucketName, objectName, int64(len(objectContent)), bytes.NewReader([]byte(objectContent)), nil, sha256sum)
return fs, disk
}
// Test Shutdown with regular conditions // Test Shutdown with regular conditions
fs, disk := prepareTest()
if err := fs.Shutdown(); err != nil { if err := fs.Shutdown(); err != nil {
t.Fatal("Cannot shutdown the FS object: ", err) t.Fatal("Cannot shutdown the FS object: ", err)
} }
removeAll(disk)
// Test Shutdown with faulty disks // Test Shutdown with faulty disk
for i := 1; i <= 5; i++ { for i := 1; i <= 5; i++ {
fs, disk := prepareTest()
fsStorage := fs.storage.(*posix)
fs.storage = newNaughtyDisk(fsStorage, map[int]error{i: errFaultyDisk}, nil) fs.storage = newNaughtyDisk(fsStorage, map[int]error{i: errFaultyDisk}, nil)
if err := fs.Shutdown(); errorCause(err) != errFaultyDisk { if err := fs.Shutdown(); errorCause(err) != errFaultyDisk {
t.Fatal(i, ", Got unexpected fs shutdown error: ", err) t.Fatal(i, ", Got unexpected fs shutdown error: ", err)
} }
removeAll(disk)
} }
} }
// TestFSLoadFormatFS - test loadFormatFS with healty and faulty disks // TestFSLoadFormatFS - test loadFormatFS with healty and faulty disks