Skip to content

Commit

Permalink
Merge pull request #984 from circus-tent/fix-travis
Browse files Browse the repository at this point in the history
Fix travis build
  • Loading branch information
k4nar authored Jul 5, 2016
2 parents abdfef1 + 9b48f34 commit 1a1041f
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 177 deletions.
14 changes: 5 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@ addons:
- libev-dev
- libevent-dev
env:
- TOX_ENV=py32
- TOX_ENV=py26
- TOX_ENV=py26-no-gevent
- TOX_ENV=py27
- TOX_ENV=py27-no-gevent
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=py26-no-gevent
- TOX_ENV=py27-no-gevent
- TOX_ENV=docs
- TOX_ENV=flake8
- TOX_ENV=circus-web
- TOX_ENV=py26
- TOX_ENV=py27

script:
- tox -e $TOX_ENV
install:
# For Python 3.2
- pip install tox "virtualenv<14"

- pip install tox

notifications:
Expand Down
4 changes: 3 additions & 1 deletion circus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def stop(self):
self.socket.disconnect(self.endpoint)
self.stream.close()

@tornado.gen.coroutine
def send_message(self, command, **props):
return self.call(make_message(command, **props))
res = yield self.call(make_message(command, **props))
raise tornado.gen.Return(res)

@tornado.gen.coroutine
def call(self, cmd):
Expand Down
5 changes: 4 additions & 1 deletion circus/pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def validate(self):
return
try:
with open(self.fname, "r") as f:
wpid = int(f.read() or 0)
try:
wpid = int(f.read() or 0)
except ValueError:
return

if wpid <= 0:
return
Expand Down
4 changes: 2 additions & 2 deletions circus/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ def info(self):

return info

def children(self):
def children(self, recursive=False):
"""Return a list of children pids."""
return [child.pid for child in get_children(self._worker)]
return [child.pid for child in get_children(self._worker, recursive)]

def is_child(self, pid):
"""Return True is the given *pid* is a child of that process."""
Expand Down
8 changes: 7 additions & 1 deletion circus/stream/redirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ def remove_fd(self, fd):

def remove_redirections(self, process):
for _, pipe in self.get_process_pipes(process):
self.remove_fd(pipe.fileno())
try:
fileno = pipe.fileno()
except ValueError:
# the pipe was already closed
pass
else:
self.remove_fd(fileno)
process.redirected = False

def change_stream(self, stream_name, redirect_writer):
Expand Down
9 changes: 9 additions & 0 deletions circus/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import zmq
from circus.util import configure_logger
from circus import logger

Expand All @@ -12,3 +13,11 @@

def setUp():
from circus import _patch # NOQA


def tearDown():
# There seems to some issue with context cleanup and Python >= 3.4
# making the tests hang at the end
# Explicitely destroying the context seems to do the trick
# cf https://github.com/zeromq/pyzmq/pull/513
zmq.Context.instance().destroy()
9 changes: 7 additions & 2 deletions circus/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@ def get_new_ioloop(self):

def tearDown(self):
for file in self.files + self.tmpfiles:
if os.path.exists(file):
try:
os.remove(file)
except OSError:
pass
for dir in self.dirs:
shutil.rmtree(dir)
try:
shutil.rmtree(dir)
except OSError:
pass

self._stop_clients()

Expand Down
45 changes: 32 additions & 13 deletions circus/tests/test_arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ class TestTrainer(TestCircus):
def setUp(self):
super(TestTrainer, self).setUp()
self.old = watcher_mod.tornado_sleep
self.to_remove = []

def tearDown(self):
watcher_mod.tornado_sleep = self.old
for path in self.to_remove:
try:
os.remove(path)
except OSError:
pass
super(TestTrainer, self).tearDown()

@tornado.gen.coroutine
Expand Down Expand Up @@ -111,6 +117,7 @@ def test_watchers(self):
def _get_cmd(self):
fd, testfile = mkstemp()
os.close(fd)
self.to_remove.append(testfile)
cmd = '%s %s %s %s' % (
PYTHON, _GENERIC,
'circus.tests.support.run_process',
Expand Down Expand Up @@ -307,7 +314,8 @@ def test_reload1(self):
truncate_file(self.test_file) # clean slate

yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START')
self.assertTrue(res) # restarted

resp = yield self._call("list", name=name)
processes2 = resp.get('pids')
Expand All @@ -328,7 +336,8 @@ def test_reload_uppercase(self):
truncate_file(self.test_file) # clean slate

yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START')
self.assertTrue(res) # restarted

resp = yield self._call("list", name=name)
processes2 = resp.get('pids')
Expand All @@ -347,7 +356,8 @@ def test_reload_sequential(self):
processes1 = resp.get('pids')
truncate_file(self.test_file) # clean slate
yield self._call("reload", sequential=True)
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)
resp = yield self._call("list", name=name)
processes2 = resp.get('pids')
self.assertNotEqual(processes1, processes2)
Expand All @@ -362,7 +372,8 @@ def test_reload2(self):

truncate_file(self.test_file) # clean slate
yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)

resp = yield self._call("list", name="test")
processes2 = resp.get('pids')
Expand All @@ -382,7 +393,8 @@ def test_reload_wid_1_worker(self):

truncate_file(self.test_file) # clean slate
yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)

resp = yield self._call("stats", name="test")
processes2 = list(resp['info'].keys())
Expand All @@ -393,7 +405,8 @@ def test_reload_wid_1_worker(self):

truncate_file(self.test_file) # clean slate
yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)

resp = yield self._call("stats", name="test")
processes3 = list(resp['info'].keys())
Expand All @@ -418,7 +431,8 @@ def test_reload_wid_4_workers(self):

truncate_file(self.test_file) # clean slate
yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)

resp = yield self._call("stats", name="test")
processes2 = list(resp['info'].keys())
Expand All @@ -429,7 +443,8 @@ def test_reload_wid_4_workers(self):

truncate_file(self.test_file) # clean slate
yield self._call("reload")
self.assertTrue(async_poll_for(self.test_file, 'START')) # restarted
res = yield async_poll_for(self.test_file, 'START') # restarted
self.assertTrue(res)

resp = yield self._call("stats", name="test")
processes3 = list(resp['info'].keys())
Expand Down Expand Up @@ -496,24 +511,28 @@ def incr_processes():
return cli.send_message('incr', name='test')

# wait for the plugin to be started
self.assertTrue(async_poll_for(datafile, 'PLUGIN STARTED'))
res = yield async_poll_for(datafile, 'PLUGIN STARTED')
self.assertTrue(res)

cli = CircusClient()
self.assertEqual(nb_processes(), 1)
incr_processes()
self.assertEqual(nb_processes(), 2)
# wait for the plugin to receive the signal
self.assertTrue(async_poll_for(datafile, 'test:spawn'))
res = yield async_poll_for(datafile, 'test:spawn')
self.assertTrue(res)
truncate_file(datafile)
incr_processes()
self.assertEqual(nb_processes(), 3)
# wait for the plugin to receive the signal
self.assertTrue(async_poll_for(datafile, 'test:spawn'))
res = yield async_poll_for(datafile, 'test:spawn')
self.assertTrue(res)
os.remove(datafile)

# XXX TODO
@tornado.testing.gen_test
def _test_singleton(self):
self._stop_runners()
yield self._stop_runners()

dummy_process = 'circus.tests.support.run_process'
self._run_circus(dummy_process, singleton=True)
Expand All @@ -529,7 +548,7 @@ def _test_udp_discovery(self):
"""test_udp_discovery: Test that when the circusd answer UDP call.
"""
self._stop_runners()
yield self._stop_runners()

dummy_process = 'circus.tests.support.run_process'
self._run_circus(dummy_process)
Expand Down
6 changes: 3 additions & 3 deletions circus/tests/test_circusctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_help_for_add_command(self):
@gen_test
def test_add(self):
yield self.start_arbiter()
async_poll_for(self.test_file, 'START')
yield async_poll_for(self.test_file, 'START')
ep = self.arbiter.endpoint

stdout, stderr = yield async_run_ctl('add test2 "%s"' % SLEEP % 1,
Expand All @@ -112,7 +112,7 @@ def test_add(self):
@gen_test
def test_add_start(self):
yield self.start_arbiter()
async_poll_for(self.test_file, 'START')
yield async_poll_for(self.test_file, 'START')
ep = self.arbiter.endpoint

stdout, stderr = yield async_run_ctl('add --start test2 "%s"'
Expand Down Expand Up @@ -144,7 +144,7 @@ def run_ctl(self, command='', endpoint=DEFAULT_ENDPOINT_DEALER):
@gen_test
def test_launch_cli(self):
yield self.start_arbiter()
async_poll_for(self.test_file, 'START')
yield async_poll_for(self.test_file, 'START')

stdout, stderr = yield self.run_ctl(endpoint=self.arbiter.endpoint)
if stderr:
Expand Down
6 changes: 6 additions & 0 deletions circus/tests/test_command_kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def setUp(self):
self.reader = StreamReader(self.stream)
self._client = None

def tearDown(self):
self._client.stop()
self.stream.close()

@property
def client(self):
if not self._client:
Expand Down Expand Up @@ -113,6 +117,7 @@ def test_exits_within_graceful_timeout(self):

yield self.assertMessage('SIGINT')
yield self.assertMessage('STOPPED')
yield self.stop_arbiter()

@tornado.testing.gen_test
def test_kills_after_graceful_timeout(self):
Expand All @@ -129,3 +134,4 @@ def test_kills_after_graceful_timeout(self):
self.assertEqual(res['status'], 'ok')

yield self.assertMessage('SIGINT')
yield self.stop_arbiter()
2 changes: 1 addition & 1 deletion circus/tests/test_command_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run_process_recursive(child_id):


@tornado.gen.coroutine
def read_from_stream(stream, desired_channel, timeout=5):
def read_from_stream(stream, desired_channel, timeout=10):
start = time.time()
accumulator = ''
if desired_channel not in channels:
Expand Down
Loading

0 comments on commit 1a1041f

Please sign in to comment.