mirror of
https://github.com/progval/irctest.git
synced 2025-04-07 07:49:52 +00:00
Automatically wait for server to start before running server tests
This commit is contained in:
@ -20,7 +20,6 @@ def main(args):
|
|||||||
import irctest.client_tests as module
|
import irctest.client_tests as module
|
||||||
elif issubclass(controller_class, BaseServerController):
|
elif issubclass(controller_class, BaseServerController):
|
||||||
import irctest.server_tests as module
|
import irctest.server_tests as module
|
||||||
_IrcTestCase.server_start_delay = args.server_start_delay
|
|
||||||
else:
|
else:
|
||||||
print(r'{}.Controller should be a subclass of '
|
print(r'{}.Controller should be a subclass of '
|
||||||
r'irctest.basecontroller.Base{{Client,Server}}Controller'
|
r'irctest.basecontroller.Base{{Client,Server}}Controller'
|
||||||
@ -41,8 +40,6 @@ parser.add_argument('module', type=str,
|
|||||||
help='The module used to run the tested program.')
|
help='The module used to run the tested program.')
|
||||||
parser.add_argument('--show-io', action='store_true',
|
parser.add_argument('--show-io', action='store_true',
|
||||||
help='Show input/outputs with the tested program.')
|
help='Show input/outputs with the tested program.')
|
||||||
parser.add_argument('--server-start-delay', type=float, default=None,
|
|
||||||
help='Number of seconds to wait before querying a server.')
|
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -2,7 +2,9 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import psutil
|
||||||
|
|
||||||
from .optional_extensions import NotImplementedByController
|
from .optional_extensions import NotImplementedByController
|
||||||
|
|
||||||
@ -47,4 +49,11 @@ class BaseServerController(_BaseController):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
def registerUser(self, case, username):
|
def registerUser(self, case, username):
|
||||||
raise NotImplementedByController('registration')
|
raise NotImplementedByController('registration')
|
||||||
|
def wait_for_port(self, proc, port):
|
||||||
|
port_open = False
|
||||||
|
while not port_open:
|
||||||
|
time.sleep(0.1)
|
||||||
|
for conn in psutil.Process(proc.pid).connections():
|
||||||
|
if conn.laddr[1] == port:
|
||||||
|
port_open = True
|
||||||
|
|
||||||
|
@ -159,10 +159,7 @@ class BaseServerTestCase(_IrcTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.find_hostname_and_port()
|
self.find_hostname_and_port()
|
||||||
kwargs = {}
|
self.controller.run(self.hostname, self.port)
|
||||||
if self.server_start_delay is not None:
|
|
||||||
kwargs['start_wait'] = self.server_start_delay
|
|
||||||
self.controller.run(self.hostname, self.port, **kwargs)
|
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.controller.kill()
|
self.controller.kill()
|
||||||
|
@ -22,7 +22,7 @@ class InspircdController(BaseServerController, DirectoryBasedController):
|
|||||||
with self.open_file('server.conf'):
|
with self.open_file('server.conf'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, hostname, port, start_wait=0.1):
|
def run(self, hostname, port):
|
||||||
assert self.proc is None
|
assert self.proc is None
|
||||||
self.create_config()
|
self.create_config()
|
||||||
with self.open_file('server.conf') as fd:
|
with self.open_file('server.conf') as fd:
|
||||||
@ -32,7 +32,7 @@ class InspircdController(BaseServerController, DirectoryBasedController):
|
|||||||
))
|
))
|
||||||
self.proc = subprocess.Popen(['inspircd', '--nofork', '--config',
|
self.proc = subprocess.Popen(['inspircd', '--nofork', '--config',
|
||||||
os.path.join(self.directory, 'server.conf')])
|
os.path.join(self.directory, 'server.conf')])
|
||||||
time.sleep(start_wait) # FIXME: do better than this to wait for InspIRCd to start
|
self.wait_for_port(self.proc, port)
|
||||||
|
|
||||||
def get_irctest_controller_class():
|
def get_irctest_controller_class():
|
||||||
return InspircdController
|
return InspircdController
|
||||||
|
@ -64,7 +64,7 @@ class MammonController(BaseServerController, DirectoryBasedController):
|
|||||||
# Mammon does not seem to handle SIGTERM very well
|
# Mammon does not seem to handle SIGTERM very well
|
||||||
self.proc.kill()
|
self.proc.kill()
|
||||||
|
|
||||||
def run(self, hostname, port, start_wait=0.5):
|
def run(self, hostname, port):
|
||||||
assert self.proc is None
|
assert self.proc is None
|
||||||
self.create_config()
|
self.create_config()
|
||||||
with self.open_file('server.yml') as fd:
|
with self.open_file('server.yml') as fd:
|
||||||
@ -75,7 +75,7 @@ class MammonController(BaseServerController, DirectoryBasedController):
|
|||||||
))
|
))
|
||||||
self.proc = subprocess.Popen(['mammond', '--nofork', #'--debug',
|
self.proc = subprocess.Popen(['mammond', '--nofork', #'--debug',
|
||||||
'--config', os.path.join(self.directory, 'server.yml')])
|
'--config', os.path.join(self.directory, 'server.yml')])
|
||||||
time.sleep(start_wait) # FIXME: do better than this to wait for Mammon to start
|
self.wait_for_port(self.proc, port)
|
||||||
|
|
||||||
def registerUser(self, case, username):
|
def registerUser(self, case, username):
|
||||||
# XXX: Move this somewhere else when
|
# XXX: Move this somewhere else when
|
||||||
|
@ -1 +1,2 @@
|
|||||||
limnoria>2012.08.04 # Needs MultipleReplacer, from 1a64f105
|
limnoria>2012.08.04 # Needs MultipleReplacer, from 1a64f105
|
||||||
|
psutil>3.1.0 # Fixes #640
|
||||||
|
Reference in New Issue
Block a user