Running the Tests - AmrAdelKhalil/mongo-connector GitHub Wiki
This page describes how to run the tests under supported versions of Python.
Requirements
-
Copy of the Mongo Connector Github repository
The tests are not included in the package from PyPI and can only be acquired by cloning this repository on Github:
git clone https://github.com/10gen-labs/mongo-connector.git -
Mongo Orchestration
Mongo Connector runs MongoDB on its own using another tool called Mongo Orchestration. This package should install automatically if you run
python setup.py test, but the Mongo Orchestration server still needs to be started manually before running the tests:mongo-orchestration startwill start the server. To stop it:
mongo-orchestration stop -
Environment variables
There are a few influential environment variables that affect the tests. These are:
DB_USERis the username to use if running the tests with authentication enabled.DB_PASSWORDis the password for the above.MONGO_PORTis the starting port for running MongoDB. Future nodes will be started on sequentially increasing ports.ES_HOSTis the hostname on which Elasticsearch is running (for mongo-connector < 2.3).ES_PORTis the port on which Elasticsearch is running (for mongo-connector < 2.3).SOLR_HOSTis the hostname on which Solr is running.SOLR_PORTis the port on which Solr is running.MO_ADDRESSis the address to use for Mongo Orchestration (i.e., hostname:port)
Test suite structure
All the tests live in the tests directory. Here is an overview of what's in each test module:
setup_cluster.pydoes not contain any tests, but contains tools for setting up and tearing down the MongoDB clusters used in the tests.test_command_replication.pytests how commands are passed and processed before being sent to a DocManager.test_config.pytests the configuration file / command-line option parser.test_elastic.pytests mongo-connector running against ElasticSearch (for mongo-connector < 2.3)test_elastic_doc_manager.pycontains unit tests for the Elastic DocManager (for mongo-connector < 2.3)test_formatters.pytests the Formatter classes, which can restructure MongoDB documents.test_mongo.pytests mongo-connector running against MongoDB (as a destination system)test_mongo_connector.pytests the front-end to mongo-connector (e.g., oplog progress file, command-line parsing, etc.)test_mongo_doc_manager.pycontains unit tests for the Mongo DocManagertest_oplog_manager.pycontains unit tests for the OplogThread class, which is responsible for tailing the MongoDB oplogtest_oplog_manager_sharded.pycontains the same tests as above, but running against a sharded environmenttest_rollbacks.pytests OplogThread under various rollback conditionstest_solr.pytests mongo-connector running against Solrtest_solr_doc_manager.pycontains unit tests for the Solr DocManagertest_synchronizer.pyalso tests OplogThread running with a dummy DocManagertest_util.pycontains unit tests for mongo-connector utilities
Running tests on the command-line
While the tests take care of setting up and tearing down MongoDB clusters on their own, the Solr and ElasticSearch tests require Solr and ElasticSearch to be running, respectively. Make sure to start these before doing a full test run!
You can run all the tests with one command (this works in all supported Python versions):
python setup.py test
In addition, you can be more selective with which tests you run (in Python > 2.6 only)! For example, if you only wanted to run the rollback tests:
python -m unittest tests.test_rollbacks
Or if you only wanted to test the remove method of the Solr DocManager:
python -m unittest tests.test_solr_doc_manager.TestSolrDocManager.test_remove
Error messages
Some of the tests are meant to generate lots of ERROR-level log messages, especially the rollback tests. mongo-connector logs exceptions it encounters while iterating the cursor in the oplog, so we see these in the console output while MongoDB clusters are being torn apart in the tests. As long as all the tests pass with an OK message, all is well.