Merge pull request #557 from harshavardhana/pr_out_fix_a_datarace_in_testcmdcatfile_testcmdcatobject_test_cases
This commit is contained in:
+9
-3
@@ -96,7 +96,7 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) {
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
data1 := "hello1"
|
||||
data1 := "hello world 1"
|
||||
binarySum1 := md5.Sum([]byte(data1))
|
||||
etag1 := base64.StdEncoding.EncodeToString(binarySum1[:])
|
||||
dataLen1 := int64(len(data1))
|
||||
@@ -500,12 +500,13 @@ func (s *CmdTestSuite) TestCatCmdObject(c *C) {
|
||||
targetReader, targetWriter := io.Pipe()
|
||||
var resultBuffer bytes.Buffer
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(sourceWriter, bytes.NewBufferString(data1))
|
||||
sourceWriter.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(&resultBuffer, targetReader)
|
||||
wg.Done()
|
||||
@@ -518,6 +519,8 @@ func (s *CmdTestSuite) TestCatCmdObject(c *C) {
|
||||
c.Assert(msg, Equals, "")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// without this there will be data races
|
||||
wg.Wait()
|
||||
c.Assert(data1, Equals, resultBuffer.String())
|
||||
|
||||
methods.AssertExpectations(c)
|
||||
@@ -550,12 +553,13 @@ func (s *CmdTestSuite) TestCatCmdFile(c *C) {
|
||||
targetReader, targetWriter := io.Pipe()
|
||||
var resultBuffer bytes.Buffer
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(sourceWriter, bytes.NewBufferString(data1))
|
||||
sourceWriter.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(&resultBuffer, targetReader)
|
||||
wg.Done()
|
||||
@@ -569,6 +573,8 @@ func (s *CmdTestSuite) TestCatCmdFile(c *C) {
|
||||
c.Assert(msg, Equals, "")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// with this there will be data races
|
||||
wg.Wait()
|
||||
c.Assert(data1, Equals, resultBuffer.String())
|
||||
|
||||
methods.AssertExpectations(c)
|
||||
|
||||
@@ -60,7 +60,18 @@ func doCopySingleSource(methods clientMethods, sourceURL, targetURL string, sour
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
return doCopy(methods, reader, md5hex, length, targetURL, targetConfig)
|
||||
// check if its a directory, construct the new TargetURL, if not fallback
|
||||
newTargetURL, err := getNewTargetURL(targetURL, sourceURL)
|
||||
switch iodine.ToError(err).(type) {
|
||||
case errIsNotDIR:
|
||||
return doCopy(methods, reader, md5hex, length, targetURL, targetConfig)
|
||||
case errIsNotBucket:
|
||||
return doCopy(methods, reader, md5hex, length, targetURL, targetConfig)
|
||||
case nil:
|
||||
return doCopy(methods, reader, md5hex, length, newTargetURL, targetConfig)
|
||||
default:
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func doCopySingleSourceRecursive(methods clientMethods, sourceURL, targetURL string, sourceConfig, targetConfig *hostConfig) error {
|
||||
|
||||
Reference in New Issue
Block a user