Issue 1:
Checklist

I have verified that the issue exists against the master branch of Celery.

This has already been asked to the discussion group first.

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the master branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

Version: Celery 4.4.7, 5.0.2, and master

Problem

I was trying to set up testing for a project using Celery using py.test and while wondering why celery_app didn't seem to have an effect (accessing celery.current_app printed out a decidedly non-test app), I think I may have found a bug in the implementation of setup_default_app (which is used by the celery_app fixture).

If you look at the implementation below (which is the same in 4.4.7, https://github.com/celery/celery/blob/d50c6cfc448e9e31384190b23f285254cb44e8a2/celery/contrib/testing/app.py), the app argument is actually never assigned to the current state globals. I believe this problem has existed for a long while, effectively making setup_default_app a no-op unless the trap is enabled.

celery/celery/contrib/testing/app.py

Lines 68 to 109
in
f50cf7d

@contextmanager

def set_trap(app):

"""Contextmanager that installs the trap app.

The trap means that anything trying to use the current or default app

will raise an exception.

"""

trap = Trap()

prev_tls = _state._tls

_state.set_default_app(trap)

class NonTLS:

current_app = trap

_state._tls = NonTLS()

yield

_state._tls = prev_tls

@contextmanager

def setup_default_app(app, use_trap=False):

"""Setup default app for testing.

Ensures state is clean after the test returns.

"""

prev_current_app = _state.get_current_app()

prev_default_app = _state.default_app

prev_finalizers = set(_state._on_app_finalizers)

prev_apps = weakref.WeakSet(_state._apps)

if use_trap:

with set_trap(app):

yield

else:

yield

_state.set_default_app(prev_default_app)

_state._tls.current_app = prev_current_app

if app is not prev_current_app:

app.close()

_state._on_app_finalizers = prev_finalizers

_state._apps = prev_apps

The celery_app pytest fixture attempts to use setup_default_app():

celery/celery/contrib/pytest.py

Lines 40 to 41
in
c3e0410

with setup_default_app(test_app, use_trap=use_trap):

yield test_app

but when the trap argument is False, no change is done to the ambient current app setting.

#6007 may be vaguely related to this.

Issue 2:
Replica sets are support by celery now for brokers and result backends, but I seem to have trouble when specifying ports on the individual nodes in the mongodb URL.

In my settings:

MONGODB_CONNECTION_URI = 'mongodb://localhost:27037,localhost:27038,localhost:27039'

The result when I run celeryd (via python manage.py celeryd):

[2012-04-16 14:16:19,389: WARNING/MainProcess] Traceback (most recent call last):

...

[2012-04-16 14:16:19,393: WARNING/MainProcess] File "/my/virtual/env/lib/python2.7/site-packages/celery/apps/worker.py", line 200, in startup_info

[2012-04-16 14:16:19,394: WARNING/MainProcess] "conninfo": self.app.broker_connection().as_uri(),

[2012-04-16 14:16:19,394: WARNING/MainProcess] File "/my/virtual/env/lib/python2.7/site-packages/celery/app/base.py", line 234, in broker_connection

[2012-04-16 14:16:19,394: WARNING/MainProcess] **transport_options or {}))

[2012-04-16 14:16:19,394: WARNING/MainProcess] File "/my/virtual/env/lib/python2.7/site-packages/kombu/connection.py", line 101, in init

[2012-04-16 14:16:19,394: WARNING/MainProcess] params.update(parse_url(hostname))

[2012-04-16 14:16:19,395: WARNING/MainProcess] File "/my/virtual/env/lib/python2.7/site-packages/kombu/utils/url.py", line 33, in parse_url

[2012-04-16 14:16:19,395: WARNING/MainProcess] scheme, host, port, user, password, path, query = _parse_url(url)

[2012-04-16 14:16:19,395: WARNING/MainProcess] File "/my/virtual/env/lib/python2.7/site-packages/kombu/utils/url.py", line 25, in _parse_url

[2012-04-16 14:16:19,395: WARNING/MainProcess] int(parts.port) if parts.port else None,

[2012-04-16 14:16:19,395: WARNING/MainProcess] File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py", line 106, in port

[2012-04-16 14:16:19,396: WARNING/MainProcess] return int(port, 10)

[2012-04-16 14:16:19,396: WARNING/MainProcess] ValueError

[2012-04-16 14:16:19,396: WARNING/MainProcess] :

[2012-04-16 14:16:19,396: WARNING/MainProcess] invalid literal for int() with base 10: '27037,localhost'

Here [1] is the full stack. So, it keeps parsing for port after the first ':', when it should break up the nodes on ',' first.

There seems to be another report of this in this comment [2] on the original celery pull request.

[1] http://pastebin.com/DvZcGdVm

[2] https://github.com/ask/kombu/pull/81#issuecomment-4327785