From e219176e8b2b0455aafa986b1c880ebcb7e46ee0 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 16 Jul 2014 20:17:10 -0400 Subject: [PATCH] More thorough peer purging test, and tidy some style things --- http/announce.go | 3 +-- http/announce_private_test.go | 1 + http/announce_test.go | 24 ++++++++++++++---------- main.go | 1 + models/models.go | 1 + 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/http/announce.go b/http/announce.go index 6cf877f..03d593a 100644 --- a/http/announce.go +++ b/http/announce.go @@ -154,8 +154,7 @@ func handleEvent(c tracker.Conn, a *models.Announce, p *models.Peer, u *models.U return } delete(t.Seeders, p.Key()) - } - if t.InLeecherPool(p) { + } else if t.InLeecherPool(p) { err = c.DeleteLeecher(t.Infohash, p.Key()) if err != nil { return diff --git a/http/announce_private_test.go b/http/announce_private_test.go index a265521..713bf98 100644 --- a/http/announce_private_test.go +++ b/http/announce_private_test.go @@ -30,6 +30,7 @@ func TestPrivateAnnounce(t *testing.T) { if err != nil { t.Fatal(err) } + defer srv.Close() baseURL := srv.URL diff --git a/http/announce_test.go b/http/announce_test.go index 13f338b..abc2f03 100644 --- a/http/announce_test.go +++ b/http/announce_test.go @@ -72,8 +72,7 @@ func TestTorrentPurging(t *testing.T) { _, status, err := fetchPath(torrentApiPath) if err != nil { t.Fatal(err) - } - if status != http.StatusOK { + } else if status != http.StatusOK { t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status)) } @@ -85,8 +84,7 @@ func TestTorrentPurging(t *testing.T) { _, status, err = fetchPath(torrentApiPath) if err != nil { t.Fatal(err) - } - if status != http.StatusNotFound { + } else if status != http.StatusNotFound { t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status)) } } @@ -110,19 +108,25 @@ func TestStalePeerPurging(t *testing.T) { _, status, err := fetchPath(torrentApiPath) if err != nil { t.Fatal(err) - } - if status != http.StatusOK { + } else if status != http.StatusOK { t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status)) } - // Let them expire. - time.Sleep(50 * time.Millisecond) + // Add a leecher. + peer = makePeerParams("peer2", false) + expected := makeResponse(1, 1, bencode.List{ + makePeerResponse("peer1"), + }) + expected["interval"] = int64(0) + checkAnnounce(peer, expected, srv, t) + + // Let them both expire. + time.Sleep(30 * time.Millisecond) _, status, err = fetchPath(torrentApiPath) if err != nil { t.Fatal(err) - } - if status != http.StatusNotFound { + } else if status != http.StatusNotFound { t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status)) } } diff --git a/main.go b/main.go index c4ef7db..721f0d9 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ func Boot() { if err != nil { glog.Fatalf("Failed to parse configuration file: %s\n", err) } + if cfg == &config.DefaultConfig { glog.V(1).Info("Using default config") } else { diff --git a/models/models.go b/models/models.go index 8766f2e..b01d2a7 100644 --- a/models/models.go +++ b/models/models.go @@ -250,6 +250,7 @@ func NewAnnounceDelta(a *Announce, p *Peer, u *User, t *Torrent, created, snatch if rawDeltaUp < 0 { rawDeltaUp = 0 } + if rawDeltaDown < 0 { rawDeltaDown = 0 }