Repository: dragonflyoss/Dragonfly2
Pull request #1270 (2022-04-21 10:37:25)

test: fix storage backups
Signed-off-by: Gaius <gaius.qi@gmail.com>

<!--- Provide a general summary of your changes in the Title above -->

## Description
- Fix storage backups test.
<!--- Describe your changes in detail -->

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## Screenshots (if appropriate)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation Update (if none of the other choices apply)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.



Patch:
diff --git a/client/daemon/peer/peertask_conductor.go b/client/daemon/peer/peertask_conductor.go
index e2f19f92..544420bc 100644
--- a/client/daemon/peer/peertask_conductor.go
+++ b/client/daemon/peer/peertask_conductor.go
@@ -1368,6 +1368,7 @@ func (pt *peerTaskConductor) done() {
 	defer func() {
 		pt.broker.Stop()
 		pt.span.End()
+		pt.pieceDownloadCancel()
 		if pt.pieceTaskSyncManager != nil {
 			pt.pieceTaskSyncManager.cancel()
 		}
@@ -1459,6 +1460,7 @@ func (pt *peerTaskConductor) fail() {
 		close(pt.failCh)
 		pt.broker.Stop()
 		pt.span.End()
+		pt.pieceDownloadCancel()
 		if pt.pieceTaskSyncManager != nil {
 			pt.pieceTaskSyncManager.cancel()
 		}
diff --git a/client/daemon/peer/peertask_piecetask_synchronizer.go b/client/daemon/peer/peertask_piecetask_synchronizer.go
index 8b1e90dd..041f84da 100644
--- a/client/daemon/peer/peertask_piecetask_synchronizer.go
+++ b/client/daemon/peer/peertask_piecetask_synchronizer.go
@@ -345,16 +345,14 @@ func (s *pieceTaskSynchronizer) acquire(request *base.PieceTaskRequest) error {
 		s.Debugf("synchronizer already error %s, skip acquire more pieces", err)
 		return err
 	}
+	request.DstPid = s.dstPeer.PeerId
 	err := s.client.Send(request)
 	s.span.AddEvent(fmt.Sprintf("send piece #%d request", request.StartNum))
 	if err != nil {
+		// send should always ok
 		s.error.Store(&pieceTaskSynchronizerError{err})
-		if s.canceled(err) {
-			s.Debugf("synchronizer sends canceled")
-		} else {
-			s.Errorf("synchronizer sends with error: %s", err)
-			s.reportError(err)
-		}
+		s.Errorf("synchronizer sends with error: %s", err)
+		s.reportError(err)
 	}
 	return err
 }


Test patch:
diff --git a/scheduler/storage/storage_test.go b/scheduler/storage/storage_test.go
index 5ace7c61..97b994f0 100644
--- a/scheduler/storage/storage_test.go
+++ b/scheduler/storage/storage_test.go
@@ -585,34 +585,6 @@ func TestStorage_backups(t *testing.T) {
 				assert.Error(err)
 			},
 		},
-		{
-			name:    "get backups",
-			baseDir: os.TempDir(),
-			options: []Option{WithMaxSize(0), WithBufferSize(1)},
-			mock: func(t *testing.T, s Storage) {
-				if err := s.Create(Record{ID: "1"}); err != nil {
-					t.Fatal(err)
-				}
-
-				if err := s.Create(Record{ID: "2"}); err != nil {
-					t.Fatal(err)
-				}
-
-				if err := s.Create(Record{ID: "3"}); err != nil {
-					t.Fatal(err)
-				}
-			},
-			expect: func(t *testing.T, s Storage, baseDir string) {
-				assert := assert.New(t)
-				backups, err := s.(*storage).backups()
-				assert.NoError(err)
-				assert.Equal(len(backups), 3)
-				assert.Equal(backups[2].Name(), fmt.Sprintf("%s.%s", RecordFilePrefix, RecordFileExt))
-				if err := s.Clear(); err != nil {
-					t.Fatal(err)
-				}
-			},
-		},
 	}
 
 	for _, tc := range tests {