2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Fix timing failures in download cancel tests

This commit is contained in:
Matt Joiner 2018-06-09 22:10:08 +10:00
parent 3d680f8afc
commit a9bdb438dc

View File

@ -9,6 +9,7 @@ import (
"net"
"os"
"path/filepath"
"reflect"
"sync"
"testing"
"time"
@ -860,24 +861,20 @@ func testDownloadCancel(t *testing.T, ps testDownloadCancelParams) {
leecherGreeting.AddClientPeer(seeder)
completes := make(map[int]bool, 3)
values:
for {
// started := time.Now()
expected := func() map[int]bool {
if ps.Cancel {
return map[int]bool{0: false, 1: false, 2: false}
} else {
return map[int]bool{0: true, 1: true, 2: true}
}
}()
for !reflect.DeepEqual(completes, expected) {
select {
case _v := <-psc.Values:
// log.Print(time.Since(started))
v := _v.(PieceStateChange)
completes[v.Index] = v.Complete
case <-time.After(100 * time.Millisecond):
break values
}
}
if ps.Cancel {
assert.EqualValues(t, map[int]bool{0: false, 1: false, 2: false}, completes)
} else {
assert.EqualValues(t, map[int]bool{0: true, 1: true, 2: true}, completes)
}
}
func TestTorrentDownloadAll(t *testing.T) {