diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 01:44:40 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 01:44:40 +0100 |
| commit | e3efacd05d8a74b2f753dd8afbfe62baa1e0770e (patch) | |
| tree | 820da05d32ae7a6f90e6247b745225516e2c13e4 /tests/integration/test_expiry.py | |
| parent | 79f4110365fe85f4377c50f0893134a8d5e45575 (diff) | |
Check for free port in the udp integration test, also speed it up by a bit
Diffstat (limited to 'tests/integration/test_expiry.py')
| -rw-r--r-- | tests/integration/test_expiry.py | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/tests/integration/test_expiry.py b/tests/integration/test_expiry.py index 4466724..5a21e57 100644 --- a/tests/integration/test_expiry.py +++ b/tests/integration/test_expiry.py | |||
| @@ -1,15 +1,19 @@ | |||
| 1 | """What the expiry sweep finds after a connection has already gone. | 1 | """What the expiry sweep finds, and what it must not find. |
| 2 | 2 | ||
| 3 | A plain request is answered and the connection closed by http_senddata, not | 3 | A plain request is answered and the connection closed by http_close, not by |
| 4 | by the sweep. If that path leaves the descriptor's slot behind, the sweep | 4 | the sweep. If that path left the descriptor's slot behind, the sweep would |
| 5 | walks into it once the client timeout has passed and frees a cookie that is | 5 | walk into it once the client timeout had passed and free a cookie that is |
| 6 | already gone. Under the sanitizer build that is reported, and teardown turns | 6 | already gone; the sanitizer build reports that and teardown turns it into a |
| 7 | it into a failure. | 7 | failure. |
| 8 | |||
| 9 | Both halves share one tracker and one wait, because the wait is the whole | ||
| 10 | cost of the test. | ||
| 8 | 11 | ||
| 9 | The two numbers below mirror OT_CLIENT_TIMEOUT and | 12 | The two numbers below mirror OT_CLIENT_TIMEOUT and |
| 10 | OT_CLIENT_TIMEOUT_CHECKINTERVAL in FEATURES_integration. | 13 | OT_CLIENT_TIMEOUT_CHECKINTERVAL in FEATURES_integration. |
| 11 | """ | 14 | """ |
| 12 | 15 | ||
| 16 | import socket | ||
| 13 | import time | 17 | import time |
| 14 | import unittest | 18 | import unittest |
| 15 | 19 | ||
| @@ -20,23 +24,16 @@ CHECK_INTERVAL = 1 | |||
| 20 | 24 | ||
| 21 | 25 | ||
| 22 | class ExpirySweep(TrackerTestCase): | 26 | class ExpirySweep(TrackerTestCase): |
| 23 | def test_an_answered_request_leaves_nothing_behind(self): | 27 | def test_the_sweep_takes_the_idle_and_leaves_the_answered(self): |
| 24 | info_hash = self.hash_for("expiry-sweep") | ||
| 25 | self.assertEqual(self.tracker.announce(info_hash)[b"complete"], 1) | ||
| 26 | |||
| 27 | # Long enough for the slot to expire and for a sweep to visit it | ||
| 28 | time.sleep(CLIENT_TIMEOUT + 3 * CHECK_INTERVAL) | ||
| 29 | |||
| 30 | self.assertEqual(self.tracker.torrent_count(), 1, "the tracker stopped serving while sweeping") | ||
| 31 | |||
| 32 | def test_a_connection_that_never_speaks_is_swept(self): | ||
| 33 | """The other side of it: a slot that really is live must still go.""" | ||
| 34 | import socket | ||
| 35 | |||
| 36 | idle = socket.create_connection(("127.0.0.1", self.tracker.port), timeout=5) | 28 | idle = socket.create_connection(("127.0.0.1", self.tracker.port), timeout=5) |
| 37 | try: | 29 | try: |
| 30 | self.assertEqual(self.tracker.announce(self.hash_for("expiry-sweep"))[b"complete"], 1) | ||
| 31 | |||
| 38 | time.sleep(CLIENT_TIMEOUT + 3 * CHECK_INTERVAL) | 32 | time.sleep(CLIENT_TIMEOUT + 3 * CHECK_INTERVAL) |
| 33 | |||
| 34 | self.assertEqual(self.tracker.torrent_count(), 1, "the tracker stopped serving while sweeping") | ||
| 35 | |||
| 39 | idle.settimeout(5) | 36 | idle.settimeout(5) |
| 40 | self.assertEqual(idle.recv(64), b"", "the tracker held a connection that never sent a request") | 37 | self.assertEqual(idle.recv(64), b"", "a connection that never sent a request was not swept") |
| 41 | finally: | 38 | finally: |
| 42 | idle.close() | 39 | idle.close() |
