diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 16:54:36 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 16:54:36 +0100 |
| commit | 1e7248b330bde4c70528ccf91535391e19294dc3 (patch) | |
| tree | f650bc5090227578602de43b3f1ea6dfa3c8e5b5 /tests | |
| parent | cfbe53da5d9ef8dad1bb3276c0b33ec2ab6e974b (diff) | |
Add a knob to help reducing memory consumption. This time: empty torrents may expire sooner
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/integration/test_config.py | 21 | ||||
| -rw-r--r-- | tests/t_clean.c | 36 |
2 files changed, 57 insertions, 0 deletions
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): | |||
| 49 | 49 | ||
| 50 | def test_so_does_an_option_it_does_not_know(self): | 50 | def test_so_does_an_option_it_does_not_know(self): |
| 51 | self.assertIn("want an address", self.refuses("listen.tcp 127.0.0.1:7999 wokers=2\n")) | 51 | self.assertIn("want an address", self.refuses("listen.tcp 127.0.0.1:7999 wokers=2\n")) |
| 52 | |||
| 53 | |||
| 54 | class EmptyTorrentTimeout(TrackerTestCase): | ||
| 55 | config = "tracker.empty_torrent_timeout 60\n" | ||
| 56 | |||
| 57 | def test_the_tracker_accepts_the_option_and_serves(self): | ||
| 58 | self.assertEqual(self.tracker.announce(self.hash_for("emptyto"))[b"complete"], 1) | ||
| 59 | self.assertNotIn("Unhandled line", self.tracker.output()) | ||
| 60 | self.assertNotIn("Parse error", self.tracker.output()) | ||
| 61 | |||
| 62 | |||
| 63 | class EmptyTorrentTimeoutThatDoesNotParse(unittest.TestCase): | ||
| 64 | def test_a_non_numeric_value_warns_but_the_tracker_serves(self): | ||
| 65 | """A scalar that will not parse warns and is ignored, unlike a listen | ||
| 66 | line, which stops the tracker.""" | ||
| 67 | tracker = Tracker("tracker.empty_torrent_timeout later\n") | ||
| 68 | try: | ||
| 69 | self.assertEqual(tracker.announce(b"emptytobad\0\0\0\0\0\0\0\0\0\0")[b"complete"], 1) | ||
| 70 | self.assertIn("Parse error", tracker.output()) | ||
| 71 | finally: | ||
| 72 | 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) { | |||
| 122 | workstruct_deinit(&ws); | 122 | workstruct_deinit(&ws); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | static void case_empty_torrent_timeout_bounds_a_counter_only_torrent(void) { | ||
| 126 | struct ot_workstruct ws; | ||
| 127 | ot_hash hash; | ||
| 128 | ot_torrent *torrent; | ||
| 129 | ot_time saved = g_empty_torrent_timeout; | ||
| 130 | |||
| 131 | test_case("the empty torrent timeout bounds a counter-only torrent's life"); | ||
| 132 | memset(hash, 0x33, sizeof(hash)); | ||
| 133 | CHECK_INT(workstruct_init(&ws, G_INBUF_SIZE), 0); | ||
| 134 | |||
| 135 | announce(&ws, &hash, 7, 1); | ||
| 136 | torrent = torrent_of(&hash); | ||
| 137 | CHECK(torrent != NULL); | ||
| 138 | torrent->down_count = 1; /* one completed download to remember it by */ | ||
| 139 | |||
| 140 | /* Age the only peer out: the torrent falls empty but keeps its count */ | ||
| 141 | step_clock_back(torrent, -OT_PEER_TIMEOUT); | ||
| 142 | CHECK_INT(clean_single_torrent(torrent), 0); | ||
| 143 | CHECK_INT(peers_in(&hash), 0); | ||
| 144 | |||
| 145 | /* Carry it a little past a short empty-torrent timeout */ | ||
| 146 | step_clock_back(torrent, -10); | ||
| 147 | |||
| 148 | /* The default, matching the torrent timeout, still holds it for the count */ | ||
| 149 | g_empty_torrent_timeout = OT_TORRENT_TIMEOUT; | ||
| 150 | CHECK_INT(clean_single_torrent(torrent), 0); | ||
| 151 | |||
| 152 | /* A timeout it has now exceeded lets the next sweep drop it */ | ||
| 153 | g_empty_torrent_timeout = OT_PEER_TIMEOUT + 5; | ||
| 154 | CHECK_INT(clean_single_torrent(torrent), 1); | ||
| 155 | |||
| 156 | g_empty_torrent_timeout = saved; | ||
| 157 | workstruct_deinit(&ws); | ||
| 158 | } | ||
| 159 | |||
| 125 | void test_clean(void) { | 160 | void test_clean(void) { |
| 126 | sigset_t hup; | 161 | sigset_t hup; |
| 127 | 162 | ||
| @@ -134,5 +169,6 @@ void test_clean(void) { | |||
| 134 | trackerlogic_init(); | 169 | trackerlogic_init(); |
| 135 | case_a_clock_that_went_back_keeps_the_swarm(); | 170 | case_a_clock_that_went_back_keeps_the_swarm(); |
| 136 | case_an_idle_swarm_still_ages_out(); | 171 | case_an_idle_swarm_still_ages_out(); |
| 172 | case_empty_torrent_timeout_bounds_a_counter_only_torrent(); | ||
| 137 | trackerlogic_deinit(); | 173 | trackerlogic_deinit(); |
| 138 | } | 174 | } |
