From a9bdb438dcb52502f7ed057bbaed74b0870edf59 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 9 Jun 2018 22:10:08 +1000 Subject: [PATCH] Fix timing failures in download cancel tests --- client_test.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/client_test.go b/client_test.go index b465279b..3705cc78 100644 --- a/client_test.go +++ b/client_test.go @@ -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) { -- 2.48.1