James Mills avatar James Mills committed fd66935

Fixed ``tests/web/test_main.py`` which was badly written.

Thanks to koobs for helping identify this issue while creating BSD ports for
circuits. As it turns out, this test was written mixing Theads and
Sub-Processes which is really evil.

See: http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

Comments (0)

Files changed (1)

tests/web/test_main.py

 import pytest
 
 from time import sleep
-from threading import Thread
+from subprocess import Popen
 from errno import ECONNREFUSED
-from subprocess import Popen
 
 from circuits.net.sockets import UDPServer, Close
 
 from .helpers import urlopen, URLError, HTTPError
 
-SERVER_CMD = ["python", "-m", "circuits.web.main"]
-
 
 def find_free_port():
     server = UDPServer(0)
     return port
 
 
-class Server(Thread):
-
-    def __init__(self, *args):
-        super(Server, self).__init__()
-
-        self.args = list(args)
-
-        self.setDaemon(True)
-
-    def run(self):
-        self.process = Popen(SERVER_CMD + self.args)
-
-    def stop(self):
-        self.process.terminate()
-        self.process.wait()
-
-
 def test():
     port = find_free_port()
 
-    server = Server("-b", "0.0.0.0:%d" % port)
-    server.start()
+    p = Popen(["python", "-m", "circuits.web.main", "-b", "0.0.0.0:%d" % port])
 
     sleep(1)
 
     s = f.read()
     assert s == b"Hello World!"
 
-    server.stop()
+    p.terminate()
+    p.wait()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.