From 1e7248b330bde4c70528ccf91535391e19294dc3 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 7 Nov 2026 16:54:36 +0100 Subject: Add a knob to help reducing memory consumption. This time: empty torrents may expire sooner --- tests/integration/test_config.py | 21 +++++++++++++++++++++ tests/t_clean.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) (limited to 'tests') diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py index 2f6bdc4..fe5cf9d 100644 --- a/tests/integration/test_config.py +++ b/tests/integration/test_config.py @@ -49,3 +49,24 @@ class AListenLineThatDoesNotParse(unittest.TestCase): def test_so_does_an_option_it_does_not_know(self): self.assertIn("want an address", self.refuses("listen.tcp 127.0.0.1:7999 wokers=2\n")) + + +class EmptyTorrentTimeout(TrackerTestCase): + config = "tracker.empty_torrent_timeout 60\n" + + def test_the_tracker_accepts_the_option_and_serves(self): + self.assertEqual(self.tracker.announce(self.hash_for("emptyto"))[b"complete"], 1) + self.assertNotIn("Unhandled line", self.tracker.output()) + self.assertNotIn("Parse error", self.tracker.output()) + + +class EmptyTorrentTimeoutThatDoesNotParse(unittest.TestCase): + def test_a_non_numeric_value_warns_but_the_tracker_serves(self): + """A scalar that will not parse warns and is ignored, unlike a listen + line, which stops the tracker.""" + tracker = Tracker("tracker.empty_torrent_timeout later\n") + try: + self.assertEqual(tracker.announce(b"emptytobad\0\0\0\0\0\0\0\0\0\0")[b"complete"], 1) + self.assertIn("Parse error", tracker.output()) + finally: + tracker._cleanup() diff --git a/tests/t_clean.c b/tests/t_clean.c index 2fadd03..0237cc6 100644 --- a/tests/t_clean.c +++ b/tests/t_clean.c @@ -122,6 +122,41 @@ static void case_an_idle_swarm_still_ages_out(void) { workstruct_deinit(&ws); } +static void case_empty_torrent_timeout_bounds_a_counter_only_torrent(void) { + struct ot_workstruct ws; + ot_hash hash; + ot_torrent *torrent; + ot_time saved = g_empty_torrent_timeout; + + test_case("the empty torrent timeout bounds a counter-only torrent's life"); + memset(hash, 0x33, sizeof(hash)); + CHECK_INT(workstruct_init(&ws, G_INBUF_SIZE), 0); + + announce(&ws, &hash, 7, 1); + torrent = torrent_of(&hash); + CHECK(torrent != NULL); + torrent->down_count = 1; /* one completed download to remember it by */ + + /* Age the only peer out: the torrent falls empty but keeps its count */ + step_clock_back(torrent, -OT_PEER_TIMEOUT); + CHECK_INT(clean_single_torrent(torrent), 0); + CHECK_INT(peers_in(&hash), 0); + + /* Carry it a little past a short empty-torrent timeout */ + step_clock_back(torrent, -10); + + /* The default, matching the torrent timeout, still holds it for the count */ + g_empty_torrent_timeout = OT_TORRENT_TIMEOUT; + CHECK_INT(clean_single_torrent(torrent), 0); + + /* A timeout it has now exceeded lets the next sweep drop it */ + g_empty_torrent_timeout = OT_PEER_TIMEOUT + 5; + CHECK_INT(clean_single_torrent(torrent), 1); + + g_empty_torrent_timeout = saved; + workstruct_deinit(&ws); +} + void test_clean(void) { sigset_t hup; @@ -134,5 +169,6 @@ void test_clean(void) { trackerlogic_init(); case_a_clock_that_went_back_keeps_the_swarm(); case_an_idle_swarm_still_ages_out(); + case_empty_torrent_timeout_bounds_a_counter_only_torrent(); trackerlogic_deinit(); } -- cgit v1.3