|
| 1 | +Testing PyMongo with mod_wsgi |
| 2 | +============================= |
| 3 | + |
| 4 | +These tests verify that PyMongo works with Apache and mod_wsgi. They are |
| 5 | +primarily intended to prevent regression of |
| 6 | +`PYTHON-353 <https://jira.mongodb.org/browse/PYTHON-353>`_, a connection leak |
| 7 | +when PyMongo 2.2 was used with Python 2.6 and mod_wsgi 2.8. However, the test |
| 8 | +may also catch concurrency bugs, or incompatibilities between PyMongo's C |
| 9 | +extensions and the way mod_wsgi manages Python sub interpreters. It is |
| 10 | +generally useful to test PyMongo in the unconventional environment that |
| 11 | +mod_wsgi creates. |
| 12 | + |
| 13 | +Test Matrix |
| 14 | +----------- |
| 15 | + |
| 16 | +PyMongo should be tested with several versions of mod_wsgi and a selection |
| 17 | +of Python versions. Each combination of mod_wsgi and Python version should |
| 18 | +be tested with both MongoClient and MongoReplicaSetClient. |
| 19 | + |
| 20 | +Setup |
| 21 | +----- |
| 22 | + |
| 23 | +Compile mod_wsgi |
| 24 | +................ |
| 25 | + |
| 26 | +Compile mod_wsgi for each combination for Python and mod_wsgi version in the |
| 27 | +test matrix. For example, to compile mod_wsgi 3.4 for Python 2.6 on a |
| 28 | +RedHat-like Linux:: |
| 29 | + |
| 30 | + sudo yum install -y httpd httpd-devel |
| 31 | + wget https://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz |
| 32 | + tar xzf mod_wsgi-3.4.tar.gz |
| 33 | + cd mod_wsgi-3.4 |
| 34 | + ./configure --with-python=/path/to/python-executable |
| 35 | + make |
| 36 | + make install |
| 37 | + |
| 38 | +To ease testing of several matrix combinations, copy the resulting |
| 39 | +``mod_wsgi.so`` to a safe place. |
| 40 | + |
| 41 | +Start mongod |
| 42 | +............ |
| 43 | + |
| 44 | +Start a standalone listening on port 27017, or a replica set with a member |
| 45 | +listening on port 27017. |
| 46 | + |
| 47 | +Configure Apache |
| 48 | +................ |
| 49 | + |
| 50 | +Copy the appropriate version of ``mod_wsgi.so`` into Apache's modules |
| 51 | +directory. Start Apache with the ``mod_wsgi_test.conf`` in this directory. |
| 52 | + |
| 53 | +Run the test |
| 54 | +------------ |
| 55 | + |
| 56 | +Run the included ``test_client.py`` script:: |
| 57 | + |
| 58 | + python test/mod_wsgi_test/test_client.py -n 2500 -t 100 parallel \ |
| 59 | + http://localhost/${mongodb_configuration}/${WORKSPACE} |
| 60 | + |
| 61 | +...where the "n" argument is the total number of requests to make to Apache, |
| 62 | +and "t" specifies the number of threads. ``mongodb_configuration`` should be |
| 63 | +"single_server" or "replica_set", depending on how you started mongod. |
| 64 | +``WORKSPACE`` is the location of the PyMongo checkout. |
| 65 | + |
| 66 | +Run this script again with different arguments to make serial requests:: |
| 67 | + |
| 68 | + python ${WORKSPACE}/test/mod_wsgi_test/test_client.py -n 25000 serial \ |
| 69 | + http://localhost/${mongodb_configuration}/${WORKSPACE} |
| 70 | + |
| 71 | +The ``test_client.py`` script merely makes HTTP requests to Apache. Its |
| 72 | +exit code is non-zero if any of its requests fails, for example with an |
| 73 | +HTTP 500. |
| 74 | + |
| 75 | +The core of the test is in the WSGI scripts: |
| 76 | +``mod_wsgi_test_single_server.wsgi`` and ``mod_wsgi_test_replica_set.wsgi``. |
| 77 | +These scripts insert some documents into MongoDB at startup, then query |
| 78 | +documents for each HTTP request. |
| 79 | + |
| 80 | +If PyMongo is leaking connections and "n" is much greater than the ulimit, |
| 81 | +the test will fail when PyMongo exhausts its file descriptors. |
| 82 | + |
| 83 | +Automation |
| 84 | +---------- |
| 85 | + |
| 86 | +At MongoDB, Inc. we use a Jenkins job that tests each combination in the |
| 87 | +matrix. The job copies the appropriate version of ``mod_wsgi.so`` into |
| 88 | +place, sets up Apache, and runs ``test_client.py`` with the proper |
| 89 | +arguments. |
0 commit comments