Skip to content

ServerSelectionTimeoutError when running in gitlab-ci on gitlab.com #68

Closed

Description

@vinjana

I am running testcontainers-python 2.6 with mongo:4.2.3. My tests work fine on my local system, but when I have them run on gitlab.com all testcontainer-using tests fail with errors of the following type:

557 ___________________ ERROR at teardown of test_create_new_run ___________________
558     @pytest.fixture(scope="function")
559     def database_connection():
560         container = MongoDbContainer('mongo:4.2.3')
561         container.start()
562         print("MongoDB connection URL: " + container.get_connection_url())
563         database = Database(MongoClient(container.get_connection_url()), "WES_Test")
564         yield database
565 >       database._db_runs().drop()
566 tests/Database_test.py:14: 
567 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
568 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/collection.py:1103: in drop
569     dbo.drop_collection(self.__name, session=session)
570 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/database.py:914: in drop_collection
571     with self.__client._socket_for_writes(session) as sock_info:
572 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/mongo_client.py:1266: in _socket_for_writes
573     server = self._select_server(writable_server_selector, session)
574 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/mongo_client.py:1253: in _select_server
575     server = topology.select_server(server_selector)
576 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/topology.py:235: in select_server
577     address))
578 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/topology.py:193: in select_servers
579     selector, server_timeout, address)
580 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
581 self = <pymongo.topology.Topology object at 0x7fc6ab1a8c88>
582 selector = <function writable_server_selector at 0x7fc6ae81af28>, timeout = 30
583 address = None
584     def _select_servers_loop(self, selector, timeout, address):
585         """select_servers() guts. Hold the lock when calling this."""
586         now = _time()
587         end_time = now + timeout
588         server_descriptions = self._description.apply_selector(
589             selector, address, custom_selector=self._settings.server_selector)
590     
591         while not server_descriptions:
592             # No suitable servers.
593             if timeout == 0 or now > end_time:
594                 raise ServerSelectionTimeoutError(
595 >                   self._error_message(selector))
596 E               pymongo.errors.ServerSelectionTimeoutError: 172.18.0.2:27017: timed out
597 /opt/conda/envs/wesnake/lib/python3.7/site-packages/pymongo/topology.py:209: ServerSelectionTimeoutError

My gitlab-ci.yml is as follows:

cache:
  paths:
    - /opt/cache/pip
    - /opt/conda/pkgs
    - /root/.conda/pkgs

services:
  - docker:dind

variables:
  DOCKER_HOST: "tcp://docker:2375"
  DOCKER_DRIVER: overlay2

before_script:
  - python -V              # For debugging
  - export PIP_CACHE_DIR="/opt/cache/pip"
  - conda init bash
  - source /root/.bashrc
  - conda info             # For debugging
  - conda config --show    # For debugging
  - conda env create -n wesnake -f environment.yaml
  - conda activate wesnake
  - pip install git+https://github.com/testcontainers/testcontainers-python.git

test:
  image: continuumio/miniconda3:latest
  script:
    - python -m pytest -v -s

run:
  image: continuumio/miniconda3:latest
  script:
    - python setup.py bdist_wheel
  artifacts:
    paths:
      - dist/*.whl

My connection-setup is as follows

@pytest.fixture(scope="function")
def database_connection():
    container = MongoDbContainer('mongo:4.2.3')
    container.start()
    database = Database(MongoClient(container.get_connection_url()), "WES_Test")
    yield database
    database._db_runs().drop()

Containers are being started and container.get_connection_url() produces URLs with variable IP numbers for the container of the form:

mongodb://172.18.0.$number:27017

I would appreciate every help with this!

Activity

  1. tillahoffmann commented on Apr 28, 2020

    @tillahoffmann
    Contributor

    The changes in #85 should address this issue. Feel free to reopen if not.

  2. vinjana commented on Apr 28, 2020

    @vinjana
    Author

    Great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions