Skip to content

Commit

Permalink
chore: optimize defer and test
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma committed Jan 19, 2022
1 parent 5083963 commit c71dd02
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,10 @@ func (pt *peerTaskConductor) Done() {
}

func (pt *peerTaskConductor) done() {
defer pt.span.End()
defer pt.broker.Stop()
defer func() {
pt.broker.Stop()
pt.span.End()
}()
var (
cost = time.Now().Sub(pt.start).Milliseconds()
success = true
Expand Down Expand Up @@ -1213,9 +1215,11 @@ func (pt *peerTaskConductor) Fail() {

func (pt *peerTaskConductor) fail() {
metrics.PeerTaskFailedCount.Add(1)
defer pt.span.End()
defer pt.broker.Stop()
defer close(pt.failCh)
defer func() {
close(pt.failCh)
pt.broker.Stop()
pt.span.End()
}()
pt.peerTaskManager.PeerTaskDone(pt.taskID)
var end = time.Now()
pt.Log().Errorf("stream peer task failed, code: %d, reason: %s", pt.failedCode, pt.failedReason)
Expand Down
1 change: 1 addition & 0 deletions client/daemon/peer/peertask_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (ptm *peerTaskManager) getOrCreatePeerTaskConductor(
logger.Debugf("peer task found: %s/%s", ptc.taskID, ptc.peerID)
return ptc, nil
}
// FIXME merge register peer tasks
ptc, err := ptm.newPeerTaskConductor(ctx, request, limit)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion client/daemon/peer/peertask_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestPeerTaskManager_TaskSuite(t *testing.T) {
},
},
{
name: "normal size scope - back source - content length - aligning",
name: "normal size scope - back source - no content length - aligning",
taskData: testBytes[:8192],
pieceParallelCount: 4,
pieceSize: 1024,
Expand Down Expand Up @@ -675,6 +675,7 @@ func (ts *testSpec) runConductorTest(assert *testifyassert.Assertions, require *
if noRunningTask {
break
}
noRunningTask = true
time.Sleep(100 * time.Millisecond)
}
assert.True(noRunningTask, "no running tasks")
Expand Down
2 changes: 1 addition & 1 deletion client/daemon/storage/storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var (
ErrTaskNotFound = errors.New("task not found")
ErrPieceNotFound = errors.New("piece not found")
ErrPieceCountNotSet = errors.New("total piece count not set")
ErrDigestNotSet = errors.New("piece digest not set")
ErrDigestNotSet = errors.New("digest not set")
ErrInvalidDigest = errors.New("invalid digest")
)

Expand Down

0 comments on commit c71dd02

Please sign in to comment.