def start(self): """Spawn the web app in testserver mode. After spawning the web app this method will wait for the web app to respond to normal requests. """ self.log.info( "start: running <%s> in <%s>." % (self.cmd, self.test_dir) ) # Spawn as a process and then wait until # the web server is ready to accept requests. # self.serverProcess = subprocess.Popen( args=self.cmd, shell=True, cwd=self.test_dir, ) pid = self.serverProcess.pid if not self.isRunning(): raise SystemError("%s did not start!" % self.cmd) #self.log.debug("start: waiting for '%s' readiness." % self.URI) net.wait_for_ready(self.URI + "/ping", timeout=2) return pid
def start(self): """Spawn the web app in testserver mode. After spawning the web app this method will wait for the web app to respond to normal requests. """ self.log.info("start: running <%s> in <%s>." % (self.cmd, self.test_dir)) # Spawn as a process and then wait until # the web server is ready to accept requests. # self.serverProcess = subprocess.Popen( args=self.cmd, shell=True, cwd=self.test_dir, ) pid = self.serverProcess.pid if not self.isRunning(): raise SystemError("%s did not start!" % self.cmd) #self.log.debug("start: waiting for '%s' readiness." % self.URI) net.wait_for_ready(self.URI + "/ping", timeout=2) return pid
def testWaitForReadyLive(self): """Test wait for ready against a basic local web service. """ # Get a free port to use for this test: port1 = net.get_free_port() web = webhelpers.BasicWeb(port=port1) self.stop_needed.append(web) # Run the web app and wait for ready should connect: web.start() result = net.wait_for_ready(web.uri) self.assertEquals(result, True)
def testNetTools(self): """Test as much of the net helper tools as I can. """ # Recover a free port to construct a uri for a ficticious web servce # we can test the fail path of the wait_for_ready with: port = net.get_free_port() class XYZ(object): def __init__(self, port): self.port = port def freeport_range(self): return self.port fpr = XYZ(port) gport = net.get_free_port(fp=fpr.freeport_range) self.assertEquals(gport, port) # use the port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('localhost', port)) # Now exlucde this port and try again. self.assertRaises(net.NoFreePort, net.get_free_port, exclude_ports=[port], fp=fpr.freeport_range) s.close() # Recover a free port to construct a uri for a ficticious web servce # we can test the fail path of the wait_for_ready with: port = net.get_free_port() ficticious_uri = "http://localhost:%d" % port # Use this made up uri and see it did indeed NOT manage to connect: result = net.wait_for_ready(ficticious_uri, retries=1) self.assertEquals(result, False) # Use this made up uri and see it did indeed NOT manage to connect: result = net.wait_for_service('localhost', port, retries=1) self.assertEquals(result, False)