]> Sergey Matveev's repositories - btrtrc.git/commitdiff
tracker/udp: Tidy up tests
authorMatt Joiner <anacrolix@gmail.com>
Wed, 3 Dec 2014 18:51:49 +0000 (12:51 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 3 Dec 2014 18:51:49 +0000 (12:51 -0600)
tracker/udp/udp_tracker_test.go

index 118d2489a8473516bb830a6c8f5882bf246ccd84..44ba25fe2ed8a75321219d25cc8b6785e471f756 100644 (file)
@@ -68,13 +68,8 @@ func TestLongWriteUDP(t *testing.T) {
 func TestShortBinaryRead(t *testing.T) {
        var data ResponseHeader
        err := binary.Read(bytes.NewBufferString("\x00\x00\x00\x01"), binary.BigEndian, &data)
-       if data.Action != 0 {
-               t.Log("optimistic binary read now works?!")
-       }
-       switch err {
-       case io.ErrUnexpectedEOF:
-       default:
-               // TODO
+       if err != io.ErrUnexpectedEOF {
+               t.FailNow()
        }
 }
 
@@ -113,6 +108,11 @@ func TestAnnounceRandomInfoHash(t *testing.T) {
        if testing.Short() {
                t.SkipNow()
        }
+       req := tracker.AnnounceRequest{
+               Event: tracker.Stopped,
+       }
+       rand.Read(req.PeerId[:])
+       rand.Read(req.InfoHash[:])
        wg := sync.WaitGroup{}
        for _, url := range []string{
                "udp://tracker.openbittorrent.com:80/announce",
@@ -131,11 +131,6 @@ func TestAnnounceRandomInfoHash(t *testing.T) {
                                t.Log(err)
                                return
                        }
-                       req := tracker.AnnounceRequest{
-                               Event: tracker.Stopped,
-                       }
-                       rand.Read(req.PeerId[:])
-                       rand.Read(req.InfoHash[:])
                        resp, err := tr.Announce(&req)
                        if err != nil {
                                t.Logf("error announcing to %s: %s", url, err)