From 8c22d577fe1bf1f5c66c82c32854bdcd9ed1b3ee Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 03:22:55 +0100 Subject: Add test for the correct order of partial scrapes --- tests/integration/test_fullscrape.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/integration/test_fullscrape.py') diff --git a/tests/integration/test_fullscrape.py b/tests/integration/test_fullscrape.py index 4059656..be7b502 100644 --- a/tests/integration/test_fullscrape.py +++ b/tests/integration/test_fullscrape.py @@ -112,3 +112,35 @@ class FullScrapeChunking(TrackerTestCase): if __name__ == "__main__": unittest.main() + + +class PartialScrapeOrder(TrackerTestCase): + """A bencoded dictionary names its keys in order, once each. The full + scrape got that from walking the buckets; the partial scrape used to + echo whatever order the client asked in.""" + + def setUp(self): + TrackerTestCase.setUp(self) + self.hashes = [bytes([i]) + b"\0" * 19 for i in (9, 1, 5, 3, 7)] + for i, h in enumerate(self.hashes): + self.tracker.announce(h, port=6001 + i, left=0) + + def scrape_many(self, hashes): + import urllib.parse + + query = "&".join("info_hash=" + urllib.parse.quote_from_bytes(h, safe="") for h in hashes) + return bdecode(self.tracker.get("/scrape?" + query)) + + def test_the_keys_come_back_in_order(self): + answer = self.scrape_many(self.hashes) + self.assertEqual(list(answer[b"files"]), sorted(self.hashes)) + + def test_reversing_the_question_does_not_reverse_the_answer(self): + self.assertEqual( + list(self.scrape_many(self.hashes[::-1])[b"files"]), list(self.scrape_many(self.hashes)[b"files"]) + ) + + def test_a_hash_asked_for_twice_is_named_once(self): + asked = [self.hashes[0], self.hashes[1], self.hashes[0]] + answer = self.scrape_many(asked) + self.assertEqual(list(answer[b"files"]), sorted({self.hashes[0], self.hashes[1]})) -- cgit v1.3