소스 검색

Fix for https://github.com/celery/celery/issues/2743
Fixes celery issue for pymongo 3+ with gevent

sukrit007 9 년 전
부모
커밋
f80e5da204
2개의 변경된 파일45개의 추가작업 그리고 4개의 파일을 삭제
  1. 0 4
      celery/backends/mongodb.py
  2. 45 0
      celery/tests/backends/test_mongodb.py

+ 0 - 4
celery/backends/mongodb.py

@@ -10,7 +10,6 @@ from __future__ import absolute_import
 
 from datetime import datetime, timedelta
 
-from kombu.syn import detect_environment
 from kombu.utils import cached_property
 from kombu.exceptions import EncodeError
 from celery import states
@@ -158,9 +157,6 @@ class MongoBackend(BaseBackend):
             conf = dict(self.options)
             conf['host'] = host
 
-            if detect_environment() != 'default':
-                conf['use_greenlets'] = True
-
             self._connection = MongoClient(**conf)
 
         return self._connection

+ 45 - 0
celery/tests/backends/test_mongodb.py

@@ -310,9 +310,15 @@ class test_MongoBackend(AppCase):
         mock_get_database.assert_called_once_with()
         mock_collection.find_one.assert_called_once_with(
             {'_id': sentinel.taskset_id})
+<<<<<<< HEAD
         self.assertEqual(
             list(sorted(['date_done', 'result', 'task_id'])),
             list(sorted(ret_val.keys())),
+=======
+        self.assertItemsEqual(
+            ['date_done', 'result', 'task_id'],
+            list(ret_val.keys()),
+>>>>>>> e758762... Fix for https://github.com/celery/celery/issues/2743
         )
 
     @patch('celery.backends.mongodb.MongoBackend._get_database')
@@ -380,3 +386,42 @@ class test_MongoBackend(AppCase):
         with self.assertRaises(ImproperlyConfigured):
             x._get_database()
         db.authenticate.assert_called_with('jerry', 'cere4l')
+
+    @patch('celery.backends.mongodb.detect_environment')
+    def test_prepare_client_options_for_ver_2(self, m_detect_env):
+        m_detect_env.return_value = 'default'
+        with patch('pymongo.version_tuple', new=(2, 6, 3)):
+            options = self.backend._prepare_client_options()
+            self.assertDictEqual(options, {
+                'max_pool_size': self.backend.max_pool_size,
+                'auto_start_request': False
+            })
+
+    @patch('celery.backends.mongodb.detect_environment')
+    def test_prepare_client_options_for_ver_2_with_gevent(self, m_detect_env):
+        m_detect_env.return_value = 'gevent'
+        with patch('pymongo.version_tuple', new=(2, 6, 3)):
+            options = self.backend._prepare_client_options()
+            self.assertDictEqual(options, {
+                'max_pool_size': self.backend.max_pool_size,
+                'auto_start_request': False,
+                'use_greenlets': True
+            })
+
+    @patch('celery.backends.mongodb.detect_environment')
+    def test_prepare_client_options_for_ver_3(self, m_detect_env):
+        m_detect_env.return_value = 'default'
+        with patch('pymongo.version_tuple', new=(3, 0, 3)):
+            options = self.backend._prepare_client_options()
+            self.assertDictEqual(options, {
+                'maxPoolSize': self.backend.max_pool_size
+            })
+
+    @patch('celery.backends.mongodb.detect_environment')
+    def test_prepare_client_options_for_ver_3_with_gevent(self, m_detect_env):
+        m_detect_env.return_value = 'gevent'
+        with patch('pymongo.version_tuple', new=(3, 0, 3)):
+            options = self.backend._prepare_client_options()
+            self.assertDictEqual(options, {
+                'maxPoolSize': self.backend.max_pool_size
+            })