summaryrefslogtreecommitdiff
path: root/tests/servers
diff options
context:
space:
mode:
authorMarten Kenbeek <marten.knbk@gmail.com>2015-12-30 13:23:50 +0100
committerTim Graham <timograham@gmail.com>2015-12-31 10:57:03 -0500
commitc87540cee5a3d5b676b9359c01bdea35f733aabb (patch)
treeb75fdd881a4d855c1e0138b372636d4af988c0a2 /tests/servers
parent89616f0c790376867ba31ada27554f40bfeb228e (diff)
Fixed #26011 -- Prevented random LiveServerTestCase test failures on Windows.
Prevented LiveServerTestCase from stealing ports used by concurrent processes on Windows.
Diffstat (limited to 'tests/servers')
-rw-r--r--tests/servers/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index dbb298e003..18102ff509 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -5,6 +5,7 @@ Tests for django.core.servers.
from __future__ import unicode_literals
import contextlib
+import errno
import os
import socket
@@ -174,3 +175,31 @@ class LiveServerDatabase(LiveServerBase):
['jane', 'robert', 'emily'],
lambda b: b.name
)
+
+
+class LiveServerPort(LiveServerBase):
+
+ def test_port_bind(self):
+ """
+ Each LiveServerTestCase binds to a unique port or fails to start a
+ server thread when run concurrently (#26011).
+ """
+ TestCase = type(str("TestCase"), (LiveServerBase,), {})
+ try:
+ TestCase.setUpClass()
+ except socket.error as e:
+ if e.ernrno == errno.EADDRINUSE:
+ # We're out of ports, LiveServerTestCase correctly fails with
+ # a socket error.
+ return
+ # Unexpected error.
+ raise
+ try:
+ # We've acquired a port, ensure our server threads acquired
+ # different addresses.
+ self.assertNotEqual(
+ self.live_server_url, TestCase.live_server_url,
+ "Acquired duplicate server addresses for server threads: %s" % self.live_server_url
+ )
+ finally:
+ TestCase.tearDownClass()