Merge branch 'server-start-wait' of https://github.com/DanielOaks/irctest

Conflicts:
	irctest/__main__.py
This commit is contained in:
Valentin Lorentz 2015-12-20 11:52:07 +01:00
commit 8318c3ff59
4 changed files with 15 additions and 13 deletions

View File

@ -20,6 +20,7 @@ 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'
@ -40,6 +41,9 @@ 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()
main(args) main(args)

View File

@ -155,7 +155,10 @@ class BaseServerTestCase(_IrcTestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.find_hostname_and_port() self.find_hostname_and_port()
self.controller.run(self.hostname, self.port) kwargs = {}
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()

View File

@ -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): def run(self, hostname, port, start_wait=0.1):
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(0.1) # FIXME: do better than this to wait for InspIRCd to start time.sleep(start_wait) # FIXME: do better than this to wait for InspIRCd to start
def get_irctest_controller_class(): def get_irctest_controller_class():
return InspircdController return InspircdController

View File

@ -1,10 +1,7 @@
import os import os
import time import time
import shutil
import tempfile
import subprocess import subprocess
from irctest import authentication
from irctest.basecontrollers import BaseServerController, DirectoryBasedController from irctest.basecontrollers import BaseServerController, DirectoryBasedController
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
@ -54,7 +51,7 @@ server:
recvq_len: 20 recvq_len: 20
""" """
class InspircdController(BaseServerController, DirectoryBasedController): class MammonController(BaseServerController, DirectoryBasedController):
def create_config(self): def create_config(self):
super().create_config() super().create_config()
with self.open_file('server.conf'): with self.open_file('server.conf'):
@ -64,7 +61,7 @@ class InspircdController(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): def run(self, hostname, port, start_wait=0.5):
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:
@ -73,11 +70,9 @@ class InspircdController(BaseServerController, DirectoryBasedController):
hostname=hostname, hostname=hostname,
port=port, port=port,
)) ))
self.proc = subprocess.Popen(['python3', '-m', 'mammon', '--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(0.5) # FIXME: do better than this to wait for Mammon to start time.sleep(start_wait) # FIXME: do better than this to wait for Mammon to start
def get_irctest_controller_class(): def get_irctest_controller_class():
return InspircdController return MammonController