mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
Add peer purging test, and ensure the purging routine runs whenever a tracker is created
This commit is contained in:
parent
0f2ed791e5
commit
a2e14f79c2
2 changed files with 41 additions and 21 deletions
|
@ -56,13 +56,8 @@ func TestPublicAnnounce(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTorrentPurging(t *testing.T) {
|
func TestTorrentPurging(t *testing.T) {
|
||||||
config := config.DefaultConfig
|
cfg := config.DefaultConfig
|
||||||
config.Tracker.Params = map[string]string{
|
srv, err := setupTracker(&cfg)
|
||||||
"purge_inactive": "200ms",
|
|
||||||
"purge_interval": "100ms",
|
|
||||||
}
|
|
||||||
|
|
||||||
srv, err := setupTracker(&config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -82,21 +77,46 @@ func TestTorrentPurging(t *testing.T) {
|
||||||
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(1010 * time.Millisecond)
|
// Remove seeder.
|
||||||
|
peer = makePeerParams("peer1", true)
|
||||||
|
peer["event"] = "stopped"
|
||||||
|
announce(peer, srv)
|
||||||
|
|
||||||
_, status, err = fetchPath(torrentApiPath)
|
_, status, err = fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if status != http.StatusNotFound {
|
||||||
|
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStalePeerPurging(t *testing.T) {
|
||||||
|
cfg := config.DefaultConfig
|
||||||
|
cfg.Announce = config.Duration{10 * time.Millisecond}
|
||||||
|
|
||||||
|
srv, err := setupTracker(&cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
torrentApiPath := srv.URL + "/torrents/" + url.QueryEscape(infoHash)
|
||||||
|
|
||||||
|
// Add one seeder.
|
||||||
|
peer := makePeerParams("peer1", true)
|
||||||
|
announce(peer, srv)
|
||||||
|
|
||||||
|
_, status, err := fetchPath(torrentApiPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove seeder.
|
// Let them expire.
|
||||||
peer = makePeerParams("peer1", true)
|
time.Sleep(50 * time.Millisecond)
|
||||||
peer["event"] = "stopped"
|
|
||||||
announce(peer, srv)
|
|
||||||
|
|
||||||
time.Sleep(1010 * time.Millisecond)
|
|
||||||
|
|
||||||
_, status, err = fetchPath(torrentApiPath)
|
_, status, err = fetchPath(torrentApiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
14
http/http.go
14
http/http.go
|
@ -36,6 +36,13 @@ func NewTracker(cfg *config.Config) (*Tracker, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go tracker.PurgeInactivePeers(
|
||||||
|
tp,
|
||||||
|
cfg.PurgeInactiveTorrents,
|
||||||
|
cfg.Announce.Duration*2,
|
||||||
|
cfg.Announce.Duration,
|
||||||
|
)
|
||||||
|
|
||||||
return &Tracker{
|
return &Tracker{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
pool: tp,
|
pool: tp,
|
||||||
|
@ -99,13 +106,6 @@ func Serve(cfg *config.Config) {
|
||||||
glog.Fatal("New: ", err)
|
glog.Fatal("New: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go tracker.PurgeInactivePeers(
|
|
||||||
t.pool,
|
|
||||||
cfg.PurgeInactiveTorrents,
|
|
||||||
cfg.Announce.Duration*2,
|
|
||||||
cfg.Announce.Duration,
|
|
||||||
)
|
|
||||||
|
|
||||||
glog.V(0).Info("Starting on ", cfg.Addr)
|
glog.V(0).Info("Starting on ", cfg.Addr)
|
||||||
graceful.Run(cfg.Addr, cfg.RequestTimeout.Duration, NewRouter(t, cfg))
|
graceful.Run(cfg.Addr, cfg.RequestTimeout.Duration, NewRouter(t, cfg))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue