diff options
Diffstat (limited to 'tests/integration/test_keepalive.py')
| -rw-r--r-- | tests/integration/test_keepalive.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/integration/test_keepalive.py b/tests/integration/test_keepalive.py index 01f02a5..f9aa468 100644 --- a/tests/integration/test_keepalive.py +++ b/tests/integration/test_keepalive.py | |||
| @@ -7,6 +7,7 @@ the request has moved on, so whether to keep the connection has to be | |||
| 7 | remembered on the connection itself. | 7 | remembered on the connection itself. |
| 8 | """ | 8 | """ |
| 9 | 9 | ||
| 10 | import time | ||
| 10 | import unittest | 11 | import unittest |
| 11 | import urllib.parse | 12 | import urllib.parse |
| 12 | 13 | ||
| @@ -106,6 +107,40 @@ class KeepAlive(TrackerTestCase): | |||
| 106 | finally: | 107 | finally: |
| 107 | c.close() | 108 | c.close() |
| 108 | 109 | ||
| 110 | def test_a_tiny_split_request_does_not_overread(self): | ||
| 111 | """A request that arrives in pieces and completes as a buffer shorter | ||
| 112 | than the dispatch literals (\"GET /\" etc.) used to read past the | ||
| 113 | exactly sized buffer. It must be rejected without a sanitizer hit.""" | ||
| 114 | c = self.tracker.connect() | ||
| 115 | try: | ||
| 116 | c.sock.sendall(b"\r\n") | ||
| 117 | time.sleep(0.05) | ||
| 118 | c.sock.sendall(b"\r\n") # completes as a 4-byte buffer | ||
| 119 | time.sleep(0.1) | ||
| 120 | finally: | ||
| 121 | c.close() | ||
| 122 | # the tracker must still answer; tearDown's stop() surfaces any sanitizer abort | ||
| 123 | answer = self.tracker.announce(self.hash_for("after-tiny"), port=6881, left=0) | ||
| 124 | self.assertNotIn(b"failure reason", answer, "the tracker stopped serving after a tiny request") | ||
| 125 | |||
| 126 | def test_a_split_request_answered_by_a_worker_does_not_spin(self): | ||
| 127 | """A reply that a worker produces does not go through the send path, | ||
| 128 | so the request stays in the buffer the read loop is reading. The loop | ||
| 129 | used to find the same request again on every pass, queue a task for | ||
| 130 | it, and never hand the thread back to the event loop.""" | ||
| 131 | for path in ("/stats", "/scrape"): | ||
| 132 | c = self.tracker.connect() | ||
| 133 | try: | ||
| 134 | c.sock.sendall(("GET %s HTTP/1.1\r\nConnection: keep-alive\r\n" % path).encode()) | ||
| 135 | time.sleep(0.2) | ||
| 136 | c.sock.sendall(b"\r\n") | ||
| 137 | self.assertIn(b"200", c.reply()[0], "%s was not answered" % path) | ||
| 138 | finally: | ||
| 139 | c.close() | ||
| 140 | |||
| 141 | answer = self.tracker.announce(self.hash_for("after-" + path), port=6881, left=0) | ||
| 142 | self.assertNotIn(b"failure reason", answer, "the tracker stopped serving after %s" % path) | ||
| 143 | |||
| 109 | 144 | ||
| 110 | if __name__ == "__main__": | 145 | if __name__ == "__main__": |
| 111 | unittest.main() | 146 | unittest.main() |
