diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/integration/test_config.py | 26 | ||||
| -rw-r--r-- | tests/integration/test_livesync.py | 53 |
2 files changed, 60 insertions, 19 deletions
diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py index 1a84fa7..2f6bdc4 100644 --- a/tests/integration/test_config.py +++ b/tests/integration/test_config.py | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | """Settings the tracker has to accept, and still work with. | 1 | """Settings the tracker has to accept, and still work with. |
| 2 | 2 | ||
| 3 | An unrecognised key makes opentracker refuse to start, so a test that it | 3 | An unrecognised key only warns, so coming up proves nothing on its own and a |
| 4 | comes up at all is a test that the key was understood. | 4 | test that cares has to look at what the tracker said. A key that is |
| 5 | recognised but cannot be parsed is another matter, and for the listen | ||
| 6 | statements it stops the tracker. | ||
| 5 | """ | 7 | """ |
| 6 | 8 | ||
| 7 | import unittest | 9 | import unittest |
| @@ -14,6 +16,7 @@ class TcpWorkers(TrackerTestCase): | |||
| 14 | 16 | ||
| 15 | def test_the_tracker_serves_with_tcp_workers_asked_for(self): | 17 | def test_the_tracker_serves_with_tcp_workers_asked_for(self): |
| 16 | self.assertEqual(self.tracker.announce(self.hash_for("tcpworkers"))[b"complete"], 1) | 18 | self.assertEqual(self.tracker.announce(self.hash_for("tcpworkers"))[b"complete"], 1) |
| 19 | self.assertNotIn("Unhandled line", self.tracker.output()) | ||
| 17 | 20 | ||
| 18 | 21 | ||
| 19 | class WorkersOnAListenStatement(unittest.TestCase): | 22 | class WorkersOnAListenStatement(unittest.TestCase): |
| @@ -27,3 +30,22 @@ class WorkersOnAListenStatement(unittest.TestCase): | |||
| 27 | self.assertEqual(complaints, [], "the tracker reported:\n" + "\n".join(complaints)) | 30 | self.assertEqual(complaints, [], "the tracker reported:\n" + "\n".join(complaints)) |
| 28 | finally: | 31 | finally: |
| 29 | tracker._cleanup() | 32 | tracker._cleanup() |
| 33 | |||
| 34 | |||
| 35 | class AListenLineThatDoesNotParse(unittest.TestCase): | ||
| 36 | """Warning and carrying on left a tracker that had been told where to | ||
| 37 | listen coming up on its default instead, which is every interface.""" | ||
| 38 | |||
| 39 | def refuses(self, line): | ||
| 40 | with self.assertRaises(AssertionError) as caught: | ||
| 41 | Tracker(line) | ||
| 42 | return str(caught.exception) | ||
| 43 | |||
| 44 | def test_an_address_that_is_not_one_stops_the_tracker(self): | ||
| 45 | self.assertIn("want an address", self.refuses("listen.tcp 10.0.0.300:7999\n")) | ||
| 46 | |||
| 47 | def test_so_does_a_port_out_of_range(self): | ||
| 48 | self.assertIn("want an address", self.refuses("listen.udp 127.0.0.1:99999\n")) | ||
| 49 | |||
| 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")) | ||
diff --git a/tests/integration/test_livesync.py b/tests/integration/test_livesync.py index 52e871f..f4cb2db 100644 --- a/tests/integration/test_livesync.py +++ b/tests/integration/test_livesync.py | |||
| @@ -10,7 +10,7 @@ import struct | |||
| 10 | import subprocess | 10 | import subprocess |
| 11 | import unittest | 11 | import unittest |
| 12 | 12 | ||
| 13 | from harness import TRACKER, TrackerTestCase | 13 | from harness import TRACKER, Tracker, TrackerTestCase |
| 14 | 14 | ||
| 15 | # enum { OT_SYNC_PEER4, OT_SYNC_PEER6 } in src/ot_livesync.c | 15 | # enum { OT_SYNC_PEER4, OT_SYNC_PEER6 } in src/ot_livesync.c |
| 16 | SYNC_PEER4 = 0 | 16 | SYNC_PEER4 = 0 |
| @@ -168,6 +168,13 @@ class LiveSyncUnconfigured(TrackerTestCase): | |||
| 168 | 168 | ||
| 169 | # RFC 2365 sets 239.192.0.0/14 aside for exactly this kind of use | 169 | # RFC 2365 sets 239.192.0.0/14 aside for exactly this kind of use |
| 170 | OWN_GROUP = "239.192.0.7" | 170 | OWN_GROUP = "239.192.0.7" |
| 171 | # A group nothing in this suite ever joins. Deliberately not the default one: | ||
| 172 | # other trackers here do join that, on ports the harness picks at random, and | ||
| 173 | # a socket bound to the wildcard address shares a port's multicast traffic | ||
| 174 | # with anything else on the host that has joined the group it is addressed | ||
| 175 | # to. Two clusters sharing a host and a port is pathological in the field but | ||
| 176 | # routine in a test suite. | ||
| 177 | UNJOINED_GROUP = "239.192.0.99" | ||
| 171 | 178 | ||
| 172 | 179 | ||
| 173 | @unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE") | 180 | @unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE") |
| @@ -182,27 +189,39 @@ class LiveSyncGroup(TrackerTestCase): | |||
| 182 | group=OWN_GROUP) | 189 | group=OWN_GROUP) |
| 183 | self.assertTrue(self.tracker.wait_until(lambda: self.tracker.torrent_count() == 1)) | 190 | self.assertTrue(self.tracker.wait_until(lambda: self.tracker.torrent_count() == 1)) |
| 184 | 191 | ||
| 185 | def test_the_default_group_is_left_alone(self): | 192 | def test_another_group_is_left_alone(self): |
| 186 | """A cluster that picked its own group should not hear the one every | 193 | """A cluster that picked its own group hears nothing from the others.""" |
| 187 | other opentracker is on.""" | ||
| 188 | info_hash = self.hash_for("not-our-group") | 194 | info_hash = self.hash_for("not-our-group") |
| 189 | self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.2", 6881, FLAG_SEEDING))])) | 195 | self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.2", 6881, FLAG_SEEDING))]), |
| 196 | group=UNJOINED_GROUP) | ||
| 190 | self.assertFalse(self.tracker.wait_until(lambda: self.tracker.torrent_count() != 0, timeout=1)) | 197 | self.assertFalse(self.tracker.wait_until(lambda: self.tracker.torrent_count() != 0, timeout=1)) |
| 191 | 198 | ||
| 192 | 199 | ||
| 193 | @unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE") | 200 | @unittest.skipUnless(has_livesync(), "this build has no WANT_SYNC_LIVE") |
| 194 | class LiveSyncGroupRefused(TrackerTestCase): | 201 | class LiveSyncGroupRefused(unittest.TestCase): |
| 195 | """A unicast address is not a group. The line is refused like any other | 202 | """A cluster that asked for a group of its own must not quietly end up on |
| 196 | bad config line, which leaves the default standing.""" | 203 | the one every other opentracker is on, so a line that does not name a |
| 204 | group stops the tracker rather than falling back.""" | ||
| 197 | 205 | ||
| 198 | config = ("livesync.cluster.group 10.0.0.1\n" | 206 | def start_with(self, group): |
| 199 | "livesync.cluster.listen 127.0.0.1:{livesync_port}\n" | 207 | return Tracker("livesync.cluster.group %s\n" |
| 200 | "livesync.cluster.node_ip 127.0.0.1\n") | 208 | "livesync.cluster.listen 127.0.0.1:{livesync_port}\n" |
| 209 | "livesync.cluster.node_ip 127.0.0.1\n" % group) | ||
| 201 | 210 | ||
| 202 | def test_the_line_is_refused(self): | 211 | def test_a_unicast_address_stops_the_tracker(self): |
| 203 | self.assertIn("Parse error", self.tracker.output()) | 212 | with self.assertRaises(AssertionError) as caught: |
| 213 | self.start_with("10.0.0.1") | ||
| 214 | self.assertIn("multicast address", str(caught.exception)) | ||
| 204 | 215 | ||
| 205 | def test_and_the_default_group_still_works(self): | 216 | def test_so_does_something_that_is_not_an_address(self): |
| 206 | info_hash = self.hash_for("fallback-group") | 217 | with self.assertRaises(AssertionError) as caught: |
| 207 | self.tracker.livesync_send(packet(SYNC_PEER4, [(info_hash, peer4("10.1.3.3", 6881, FLAG_SEEDING))])) | 218 | self.start_with("not-an-address") |
| 208 | self.assertTrue(self.tracker.wait_until(lambda: self.tracker.torrent_count() == 1)) | 219 | self.assertIn("multicast address", str(caught.exception)) |
| 220 | |||
| 221 | def test_a_group_at_either_end_of_the_range_is_taken(self): | ||
| 222 | for group in ("224.0.0.1", "239.255.255.255"): | ||
| 223 | tracker = self.start_with(group) | ||
| 224 | try: | ||
| 225 | self.assertEqual(tracker.torrent_count(), 0) | ||
| 226 | finally: | ||
| 227 | tracker.stop() | ||
