Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: total pieces not set when back source #908

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/daemon/peer/piece_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func (pm *pieceManager) DownloadSource(ctx context.Context, pt Task, request *sc
},
ContentLength: contentLength,
GenPieceDigest: true,
TotalPieces: pt.GetTotalPieces(),
}); err != nil {
log.Errorf("update task failed %s", err)
}
Expand Down
11 changes: 9 additions & 2 deletions client/daemon/peer/piece_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/golang/mock/gomock"
testifyassert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"

"d7y.io/dragonfly/v2/client/clientutil"
"d7y.io/dragonfly/v2/client/config"
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestPieceManager_DownloadSource(t *testing.T) {
checkDigest bool
}{
{
name: "multiple pieces with content length",
name: "multiple pieces with content length, check digest",
pieceSize: 1024,
checkDigest: true,
withContentLength: true,
Expand All @@ -95,7 +96,7 @@ func TestPieceManager_DownloadSource(t *testing.T) {
withContentLength: true,
},
{
name: "multiple pieces without content length",
name: "multiple pieces without content length, check digest",
pieceSize: 1024,
checkDigest: true,
withContentLength: false,
Expand Down Expand Up @@ -131,12 +132,18 @@ func TestPieceManager_DownloadSource(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
/********** prepare test start **********/
mockPeerTask := NewMockTask(ctrl)
var totalPieces = &atomic.Int32{}
mockPeerTask.EXPECT().SetContentLength(gomock.Any()).AnyTimes().DoAndReturn(
func(arg0 int64) error {
return nil
})
mockPeerTask.EXPECT().SetTotalPieces(gomock.Any()).AnyTimes().DoAndReturn(
func(arg0 int32) {
totalPieces.Store(arg0)
})
mockPeerTask.EXPECT().GetTotalPieces().AnyTimes().DoAndReturn(
func() int32 {
return totalPieces.Load()
})
mockPeerTask.EXPECT().GetPeerID().AnyTimes().DoAndReturn(
func() string {
Expand Down