fix: content length is zero when task succeed (#1732)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
327cf4493e
commit
04dabff01e
|
|
@ -148,7 +148,7 @@ func NewTask(id, url string, taskType commonv1.TaskType, meta *commonv1.UrlMeta,
|
||||||
URL: url,
|
URL: url,
|
||||||
Type: taskType,
|
Type: taskType,
|
||||||
URLMeta: meta,
|
URLMeta: meta,
|
||||||
ContentLength: atomic.NewInt64(0),
|
ContentLength: atomic.NewInt64(-1),
|
||||||
TotalPieceCount: atomic.NewInt32(0),
|
TotalPieceCount: atomic.NewInt32(0),
|
||||||
BackToSourceLimit: atomic.NewInt32(0),
|
BackToSourceLimit: atomic.NewInt32(0),
|
||||||
BackToSourcePeers: set.NewSafeSet[string](),
|
BackToSourcePeers: set.NewSafeSet[string](),
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func TestTask_NewTask(t *testing.T) {
|
||||||
assert.Equal(task.URL, mockTaskURL)
|
assert.Equal(task.URL, mockTaskURL)
|
||||||
assert.EqualValues(task.URLMeta, mockTaskURLMeta)
|
assert.EqualValues(task.URLMeta, mockTaskURLMeta)
|
||||||
assert.Empty(task.DirectPiece)
|
assert.Empty(task.DirectPiece)
|
||||||
assert.Equal(task.ContentLength.Load(), int64(0))
|
assert.Equal(task.ContentLength.Load(), int64(-1))
|
||||||
assert.Equal(task.TotalPieceCount.Load(), int32(0))
|
assert.Equal(task.TotalPieceCount.Load(), int32(0))
|
||||||
assert.Equal(task.BackToSourceLimit.Load(), int32(200))
|
assert.Equal(task.BackToSourceLimit.Load(), int32(200))
|
||||||
assert.Equal(task.BackToSourcePeers.Len(), uint(0))
|
assert.Equal(task.BackToSourcePeers.Len(), uint(0))
|
||||||
|
|
|
||||||
|
|
@ -806,14 +806,14 @@ func (s *Service) handleTaskSuccess(ctx context.Context, task *resource.Task, re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update task's resource total piece count and content length.
|
||||||
|
task.TotalPieceCount.Store(result.TotalPieceCount)
|
||||||
|
task.ContentLength.Store(result.ContentLength)
|
||||||
|
|
||||||
if err := task.FSM.Event(resource.TaskEventDownloadSucceeded); err != nil {
|
if err := task.FSM.Event(resource.TaskEventDownloadSucceeded); err != nil {
|
||||||
task.Log.Errorf("task fsm event failed: %s", err.Error())
|
task.Log.Errorf("task fsm event failed: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update task's resource total piece count and content length.
|
|
||||||
task.TotalPieceCount.Store(result.TotalPieceCount)
|
|
||||||
task.ContentLength.Store(result.ContentLength)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conditions for the task to switch to the TaskStateSucceeded are:
|
// Conditions for the task to switch to the TaskStateSucceeded are:
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ func TestService_RegisterPeerTask(t *testing.T) {
|
||||||
) {
|
) {
|
||||||
mockPeer.Task.FSM.SetState(resource.TaskStateSucceeded)
|
mockPeer.Task.FSM.SetState(resource.TaskStateSucceeded)
|
||||||
mockPeer.Task.StorePeer(mockSeedPeer)
|
mockPeer.Task.StorePeer(mockSeedPeer)
|
||||||
|
mockPeer.Task.ContentLength.Store(0)
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
mr.TaskManager().Return(taskManager).Times(1),
|
mr.TaskManager().Return(taskManager).Times(1),
|
||||||
mt.LoadOrStore(gomock.Any()).Return(mockPeer.Task, true).Times(1),
|
mt.LoadOrStore(gomock.Any()).Return(mockPeer.Task, true).Times(1),
|
||||||
|
|
@ -1266,7 +1267,7 @@ func TestService_StatTask(t *testing.T) {
|
||||||
assert.EqualValues(task, &schedulerv1.Task{
|
assert.EqualValues(task, &schedulerv1.Task{
|
||||||
Id: mockTaskID,
|
Id: mockTaskID,
|
||||||
Type: commonv1.TaskType_Normal,
|
Type: commonv1.TaskType_Normal,
|
||||||
ContentLength: 0,
|
ContentLength: -1,
|
||||||
TotalPieceCount: 0,
|
TotalPieceCount: 0,
|
||||||
State: resource.TaskStatePending,
|
State: resource.TaskStatePending,
|
||||||
PeerCount: 0,
|
PeerCount: 0,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue