Avoid race in test
This commit is contained in:
parent
1f3eace72f
commit
37272a391b
|
@ -873,10 +873,14 @@ func testDownloadCancel(t *testing.T, ps testDownloadCancelParams) {
|
|||
assert.True(t, new)
|
||||
psc := leecherGreeting.SubscribePieceStateChanges()
|
||||
defer psc.Close()
|
||||
leecherGreeting.DownloadAll()
|
||||
|
||||
leecherGreeting.cl.mu.Lock()
|
||||
leecherGreeting.downloadPiecesLocked(0, leecherGreeting.numPieces())
|
||||
if ps.Cancel {
|
||||
leecherGreeting.CancelPieces(0, leecherGreeting.NumPieces())
|
||||
leecherGreeting.cancelPiecesLocked(0, leecherGreeting.NumPieces())
|
||||
}
|
||||
leecherGreeting.cl.mu.Unlock()
|
||||
|
||||
addClientPeer(leecherGreeting, seeder)
|
||||
completes := make(map[int]bool, 3)
|
||||
values:
|
||||
|
|
8
t.go
8
t.go
|
@ -152,6 +152,10 @@ func (t *Torrent) deleteReader(r *reader) {
|
|||
func (t *Torrent) DownloadPieces(begin, end int) {
|
||||
t.cl.mu.Lock()
|
||||
defer t.cl.mu.Unlock()
|
||||
t.downloadPiecesLocked(begin, end)
|
||||
}
|
||||
|
||||
func (t *Torrent) downloadPiecesLocked(begin, end int) {
|
||||
for i := begin; i < end; i++ {
|
||||
if t.pieces[i].priority.Raise(PiecePriorityNormal) {
|
||||
t.updatePiecePriority(i)
|
||||
|
@ -162,6 +166,10 @@ func (t *Torrent) DownloadPieces(begin, end int) {
|
|||
func (t *Torrent) CancelPieces(begin, end int) {
|
||||
t.cl.mu.Lock()
|
||||
defer t.cl.mu.Unlock()
|
||||
t.cancelPiecesLocked(begin, end)
|
||||
}
|
||||
|
||||
func (t *Torrent) cancelPiecesLocked(begin, end int) {
|
||||
for i := begin; i < end; i++ {
|
||||
p := &t.pieces[i]
|
||||
if p.priority == PiecePriorityNone {
|
||||
|
|
Loading…
Reference in New Issue