Skip to content

Commit 2c7b975

Browse files
committed
Fixed test leaving mongodb/redis started, tag as 0.1.11
1 parent 1d4b23e commit 2c7b975

File tree

7 files changed

+59
-47
lines changed

7 files changed

+59
-47
lines changed

Diff for: mrq/bin/mrq_run.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sys.path.insert(0, os.getcwd())
2020

2121
from mrq import config, utils
22-
from mrq.context import set_current_config, set_current_job
22+
from mrq.context import set_current_config, set_current_job, connections
2323
from mrq.job import queue_job
2424
from mrq.utils import load_class_by_path
2525

@@ -60,5 +60,8 @@ def main():
6060
ret = job.perform()
6161
print json.dumps(ret) # pylint: disable=no-member
6262

63+
# This shouldn't be needed as the process will exit and close any remaining sockets
64+
# connections.redis.connection_pool.disconnect()
65+
6366
if __name__ == "__main__":
6467
main()

Diff for: mrq/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def add_parser_args(parser, config_type):
102102
parser.add_argument(
103103
'--redis_timeout',
104104
action='store',
105-
default=20,
105+
default=30,
106106
help='Redis connection pool timeout to wait for an available connection')
107107

108108
parser.add_argument(

Diff for: mrq/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.1.10"
1+
VERSION = "0.1.11"

Diff for: tests/conftest.py

-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ def send_task(self, path, params, **kwargs):
226226
return self.send_tasks(path, [params], **kwargs)[0]
227227

228228
def send_task_cli(self, path, params, queue=None, **kwargs):
229-
if not self.started and queue:
230-
self.start()
231229

232230
cli = ["python", "mrq/bin/mrq_run.py", "--quiet"]
233231
if queue:

Diff for: tests/test_cli.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ def test_cli_run_blocking(worker):
99

1010
assert result == 42
1111

12+
worker.stop_deps()
13+
1214

1315
def test_cli_run_nonblocking(worker):
1416

15-
worker.start_deps()
17+
worker.start()
1618

1719
job_id1 = worker.send_task_cli(
1820
"tests.tasks.general.Add", {"a": 41, "b": 1}, queue="default")
@@ -25,3 +27,5 @@ def test_cli_run_nonblocking(worker):
2527

2628
assert job1.data["status"] == "success"
2729
assert job1.data["result"] == 42
30+
31+
worker.stop()

Diff for: tests/test_context.py

-41
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import json
2-
import time
32
import os
4-
import pytest
53

64

75
def test_context_get(worker):
@@ -98,42 +96,3 @@ def test_context_setup():
9896

9997
assert out.endswith("42\ntestname1\n")
10098

101-
102-
@pytest.mark.parametrize(["gevent_count", "subpool_size", "iterations", "expected_clients"], [
103-
(None, None, 1, 1), # single task opens a single connection
104-
(None, None, 2, 1),
105-
(None, 10, 1, 10), # single task with subpool of 10 opens 10 connections
106-
(None, 10, 2, 10),
107-
(None, 200, 1, 100), # single task with subpool of 200 opens 100 connections, we reach the max_connections limit
108-
(None, 200, 2, 100),
109-
(4, None, 1, 4), # 4 gevent workers with a single task each : 4 connections
110-
(4, None, 2, 4),
111-
(2, 2, 1, 4), # 2 gevent workers with 2 single tasks each : 4 connections
112-
(2, 2, 2, 4),
113-
114-
])
115-
def test_redis_disconnections(gevent_count, subpool_size, iterations, expected_clients, worker):
116-
""" mrq.context.connections is not the actual connections pool that the worker uses.
117-
this worker's pool is not accessible from here, since it runs in a different thread.
118-
"""
119-
from mrq.context import connections
120-
121-
gevent_count = gevent_count if gevent_count is not None else 1
122-
123-
get_clients = lambda: [c for c in connections.redis.client_list() if c.get("cmd") != "client"]
124-
# 1. start the worker and asserts that there is a redis client connected
125-
kwargs = {"flags": "--redis_max_connections 100"}
126-
if gevent_count:
127-
kwargs["flags"] += " --gevent %s" % gevent_count
128-
129-
worker.start(**kwargs)
130-
131-
for i in range(0, iterations):
132-
# sending tasks has the good side effect to wait for the worker to connect to redis
133-
worker.send_tasks("tests.tasks.redis.Disconnections", [{"subpool_size": subpool_size}] * gevent_count)
134-
135-
assert len(get_clients()) == expected_clients
136-
137-
# 2. kill the worker and make sure that the connection was closed
138-
worker.stop(deps=False) # so that we still have access to redis
139-
assert len(get_clients()) == 0

Diff for: tests/test_disconnects.py

+48
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,51 @@ def test_disconnects_service_during_task(worker, p_service):
3434

3535
# Result should be there without issues
3636
assert Job(job_id1).fetch().data["result"] == 42
37+
38+
39+
@pytest.mark.parametrize(["gevent_count", "subpool_size", "iterations", "expected_clients"], [
40+
(None, None, 1, 1), # single task opens a single connection
41+
(None, None, 2, 1),
42+
(None, 10, 1, 10), # single task with subpool of 10 opens 10 connections
43+
(None, 10, 2, 10),
44+
(None, 200, 1, 100), # single task with subpool of 200 opens 100 connections, we reach the max_connections limit
45+
(None, 200, 2, 100),
46+
(4, None, 1, 4), # 4 gevent workers with a single task each : 4 connections
47+
(4, None, 2, 4),
48+
(2, 2, 1, 4), # 2 gevent workers with 2 single tasks each : 4 connections
49+
(2, 2, 2, 4),
50+
51+
])
52+
def test_redis_disconnections(gevent_count, subpool_size, iterations, expected_clients, worker):
53+
""" mrq.context.connections is not the actual connections pool that the worker uses.
54+
this worker's pool is not accessible from here, since it runs in a different thread.
55+
"""
56+
from mrq.context import connections
57+
58+
worker.start_deps()
59+
60+
gevent_count = gevent_count if gevent_count is not None else 1
61+
62+
get_clients = lambda: [c for c in connections.redis.client_list() if c.get("cmd") != "client"]
63+
64+
assert len(get_clients()) == 0
65+
66+
# 1. start the worker and asserts that there is a redis client connected
67+
kwargs = {"flags": "--redis_max_connections 100", "deps": False}
68+
if gevent_count:
69+
kwargs["flags"] += " --gevent %s" % gevent_count
70+
71+
worker.start(**kwargs)
72+
73+
for i in range(0, iterations):
74+
# sending tasks has the good side effect to wait for the worker to connect to redis
75+
worker.send_tasks("tests.tasks.redis.Disconnections", [{"subpool_size": subpool_size}] * gevent_count)
76+
77+
assert len(get_clients()) == expected_clients
78+
79+
# 2. kill the worker and make sure that the connection was closed
80+
worker.stop(deps=False) # so that we still have access to redis
81+
82+
assert len(get_clients()) == 0
83+
84+
worker.stop_deps()

0 commit comments

Comments
 (0)