tests: Fix test server init - cleanup (#3806)

master
Karthic Rao 8 years ago committed by Harshavardhana
parent 472fa4a6ca
commit 2b0ed21f08
  1. 20
      cmd/benchmark-utils_test.go
  2. 28
      cmd/fs-v1-rwpool.go
  3. 55
      cmd/test-utils_test.go

@ -28,25 +28,9 @@ import (
humanize "github.com/dustin/go-humanize"
)
// Prepare benchmark backend
// Prepare XL/FS backend for benchmark.
func prepareBenchmarkBackend(instanceType string) (ObjectLayer, []string, error) {
switch instanceType {
// Total number of disks for FS backend is set to 1.
case FSTestStr:
obj, disk, err := prepareFS()
if err != nil {
return nil, nil, err
}
return obj, []string{disk}, nil
// Total number of disks for XL backend is set to 16.
case XLTestStr:
return prepareXL()
}
obj, disk, err := prepareFS()
if err != nil {
return nil, nil, err
}
return obj, []string{disk}, nil
return prepareTestBackend(instanceType)
}
// Benchmark utility functions for ObjectLayer.PutObject().

@ -50,7 +50,6 @@ func (fsi *fsIOPool) Open(path string) (*lock.RLockedFile, error) {
fsi.Lock()
rlkFile, ok := fsi.readersMap[path]
// File reference exists on map, validate if its
// really closed and we are safe to purge it.
if ok && rlkFile != nil {
@ -76,8 +75,9 @@ func (fsi *fsIOPool) Open(path string) (*lock.RLockedFile, error) {
// read lock mode.
if !ok {
var err error
var newRlkFile *lock.RLockedFile
// Open file for reading.
rlkFile, err = lock.RLockedOpenFile(preparePath(path))
newRlkFile, err = lock.RLockedOpenFile(preparePath(path))
if err != nil {
if os.IsNotExist(err) {
return nil, errFileNotFound
@ -95,6 +95,30 @@ func (fsi *fsIOPool) Open(path string) (*lock.RLockedFile, error) {
// Save new reader on the map.
fsi.Lock()
rlkFile, ok = fsi.readersMap[path]
if ok && rlkFile != nil {
// If the file is closed and not removed from map is a bug.
if rlkFile.IsClosed() {
// Log this as an error.
errorIf(errUnexpected, "Unexpected entry found on the map %s", path)
// Purge the cached lock path from map.
delete(fsi.readersMap, path)
// Save the newly acquired read locked file.
rlkFile = newRlkFile
} else {
// Increment the lock ref, since the file is not closed yet
// and caller requested to read the file again.
rlkFile.IncLockRef()
newRlkFile.Close()
}
} else {
// Save the newly acquired read locked file.
rlkFile = newRlkFile
}
// Save the rlkFile back on the map.
fsi.readersMap[path] = rlkFile
fsi.Unlock()
}

@ -75,19 +75,11 @@ func prepareFS() (ObjectLayer, string, error) {
if err != nil {
return nil, "", err
}
endpoints, err := parseStorageEndpoints(fsDirs)
if err != nil {
return nil, "", err
}
fsPath, err := url.QueryUnescape(endpoints[0].String())
if err != nil {
return nil, "", err
}
obj, err := newFSObjectLayer(fsPath)
obj, err := newFSObjectLayer(fsDirs[0])
if err != nil {
return nil, "", err
}
return obj, endpoints[0].Path, nil
return obj, fsDirs[0], nil
}
func prepareXL() (ObjectLayer, []string, error) {
@ -193,16 +185,18 @@ type TestServer struct {
SrvCmdCfg serverCmdConfig
}
// UnstartedTestServer - Configures a temp FS/XL backend,
// initializes the endpoints and configures the test server.
// The server should be started using the Start() method.
func UnstartedTestServer(t TestErrHandler, instanceType string) TestServer {
// create an instance of TestServer.
testServer := TestServer{}
// create temporary backend for the test server.
nDisks := 16
disks, err := getRandomDisks(nDisks)
// return FS/XL object layer and temp backend.
objLayer, disks, err := prepareTestBackend(instanceType)
if err != nil {
t.Fatal("Failed to create disks for the backend")
t.Fatal(err)
}
// set the server configuration.
root, err := newTestConfig(globalMinioDefaultRegion)
if err != nil {
t.Fatalf("%s", err)
@ -212,19 +206,15 @@ func UnstartedTestServer(t TestErrHandler, instanceType string) TestServer {
// Get credential.
credentials := serverConfig.GetCredential()
testServer.Root = root
testServer.Obj = objLayer
testServer.Disks, err = parseStorageEndpoints(disks)
if err != nil {
t.Fatalf("Unexpected error %s", err)
t.Fatalf("Unexpected error %v", err)
}
testServer.Root = root
testServer.AccessKey = credentials.AccessKey
testServer.SecretKey = credentials.SecretKey
objLayer, _, err := initObjectLayer(testServer.Disks)
if err != nil {
t.Fatalf("Failed obtaining Temp Backend: <ERROR> %s", err)
}
srvCmdCfg := serverCmdConfig{
endpoints: testServer.Disks,
}
@ -238,10 +228,9 @@ func UnstartedTestServer(t TestErrHandler, instanceType string) TestServer {
// Run TestServer.
testServer.Server = httptest.NewUnstartedServer(httpHandler)
// obtain server address.
srvCmdCfg.serverAddr = testServer.Server.Listener.Addr().String()
testServer.Obj = objLayer
globalObjLayerMutex.Lock()
globalObjectAPI = objLayer
globalObjLayerMutex.Unlock()
@ -1774,6 +1763,24 @@ func initAPIHandlerTest(obj ObjectLayer, endpoints []string) (string, http.Handl
return bucketName, f, nil
}
// prepare test backend.
// create FS/XL bankend.
// return object layer, backend disks.
func prepareTestBackend(instanceType string) (ObjectLayer, []string, error) {
switch instanceType {
// Total number of disks for XL backend is set to 16.
case XLTestStr:
return prepareXL()
default:
// return FS backend by default.
obj, disk, err := prepareFS()
if err != nil {
return nil, nil, err
}
return obj, []string{disk}, nil
}
}
// ExecObjectLayerAPIAnonTest - Helper function to validate object Layer API handler
// response for anonymous/unsigned and unknown signature type HTTP request.

Loading…
Cancel
Save