greyrook / dockerdb Goto Github PK
View Code? Open in Web Editor NEWRunning databases inside tempory docker for testing purposes
License: Other
Running databases inside tempory docker for testing purposes
License: Other
The mongo fixture does not support using replica sets for the test. Sadly for some features of mongodb to work (like changeStreams) the mongod service needs to be started with a replica set, even if there is no second container.
Using newer versions of mongodb (like 3.6.8) there are 2 exceptions while trying to factory_reset the databases, specifically while trying to drop the 'admin' database and the 'config' database.
When dropping 'admin':
pymongo.errors.OperationFailure: Dropping the 'admin' database is prohibited.
When dropping 'config':
pymongo.errors.OperationFailure: Direct writes against config.transactions cannot be performed using a transaction or on a session.
Traceback:
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/dockerdb/pytest.py:30: in get_service
service.factory_reset()
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/dockerdb/init.py:140: in factory_reset
client.drop_database(db)
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/pymongo/mongo_client.py:1541: in drop_database
session=session)
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/pymongo/database.py:439: in _command
client=self.__client)
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/pymongo/pool.py:496: in command
collation=collation)
../../lnva2-ira6Ubzw/lib/python3.6/site-packages/pymongo/network.py:125: in command
parse_write_concern_error=parse_write_concern_error)
Dockerdb generally works even from within another docker container, as long as the docker.sock is mounted. It makes local testing a breeze, since the docker-compose / Dockerfile already encapsulates the project setup, independent of the host environment.
The restore
option fails to set the data on the database when a pytest is executed from within a docker container. The dump path should exists, but the exec_run
returns the following error:
('Exit code', 1, "2020-03-10T02:19:26.710+0000 Failed: mongorestore target
'/tmp/tmpc_pieAtmp_1583806764_mongo_0/dump' invalid: stat
/tmp/tmpc_pieAtmp_1583806764_mongo_0/dump: no such file or directory\n")
Executing the same test outside the docker container successfully restores the data. The problem seems to be related to the way the service shares data, using a shared volume. The problem can be locally reproduced but fixed by mounting /tmp
in the main container.
conftest.py
BASE_PATH = os.path.dirname(__file__)
DUMP_PATH = os.path.join(BASE_PATH, 'dump')
mongo = dockerdb.mongo_pytest.mongo_fixture(versions=["3.5"], restore=DUMP_PATH)
docker exec docker_container pytest
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.