More thorough peer purging test, and tidy some style things
This commit is contained in:
parent
242892eb79
commit
e219176e8b
5 changed files with 18 additions and 12 deletions
|
@ -154,8 +154,7 @@ func handleEvent(c tracker.Conn, a *models.Announce, p *models.Peer, u *models.U
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete(t.Seeders, p.Key())
|
delete(t.Seeders, p.Key())
|
||||||
}
|
} else if t.InLeecherPool(p) {
|
||||||
if t.InLeecherPool(p) {
|
|
||||||
err = c.DeleteLeecher(t.Infohash, p.Key())
|
err = c.DeleteLeecher(t.Infohash, p.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -30,6 +30,7 @@ func TestPrivateAnnounce(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
baseURL := srv.URL
|
baseURL := srv.URL
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,7 @@ func TestTorrentPurging(t *testing.T) {
|
||||||
_, status, err := fetchPath(torrentApiPath)
|
_, status, err := fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if status != http.StatusOK {
|
||||||
if status != http.StatusOK {
|
|
||||||
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +84,7 @@ func TestTorrentPurging(t *testing.T) {
|
||||||
_, status, err = fetchPath(torrentApiPath)
|
_, status, err = fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if status != http.StatusNotFound {
|
||||||
if status != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
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)
|
_, status, err := fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if status != http.StatusOK {
|
||||||
if status != http.StatusOK {
|
|
||||||
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let them expire.
|
// Add a leecher.
|
||||||
time.Sleep(50 * time.Millisecond)
|
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)
|
_, status, err = fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if status != http.StatusNotFound {
|
||||||
if status != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
main.go
1
main.go
|
@ -60,6 +60,7 @@ func Boot() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to parse configuration file: %s\n", err)
|
glog.Fatalf("Failed to parse configuration file: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg == &config.DefaultConfig {
|
if cfg == &config.DefaultConfig {
|
||||||
glog.V(1).Info("Using default config")
|
glog.V(1).Info("Using default config")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -250,6 +250,7 @@ func NewAnnounceDelta(a *Announce, p *Peer, u *User, t *Torrent, created, snatch
|
||||||
if rawDeltaUp < 0 {
|
if rawDeltaUp < 0 {
|
||||||
rawDeltaUp = 0
|
rawDeltaUp = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if rawDeltaDown < 0 {
|
if rawDeltaDown < 0 {
|
||||||
rawDeltaDown = 0
|
rawDeltaDown = 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue