]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix timing failures in download cancel tests
authorMatt Joiner <anacrolix@gmail.com>
Sat, 9 Jun 2018 12:10:08 +0000 (22:10 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 9 Jun 2018 23:20:33 +0000 (09:20 +1000)
client_test.go

index b465279b7e7936cb3f4c94945fa9753f54869d21..3705cc78b9b4f869999291592a964e81bcb2d540 100644 (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) {