Skip to content

Commit

Permalink
Testing: Use unique names when running multiple test container instances
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Feb 9, 2024
1 parent 3a8e9bf commit 224bba5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cratedb_toolkit/testing/testcontainers/cratedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
password: Optional[str] = None,
dbname: Optional[str] = None,
cmd_opts: Optional[dict] = None,
name: Optional[str] = None,
**kwargs,
) -> None:
"""
Expand All @@ -89,7 +90,7 @@ def __init__(
"""
super().__init__(image=image, **kwargs)

self._name = "testcontainers-cratedb"
self._name = name or "testcontainers-cratedb"

cmd_opts = cmd_opts or {}
self._command = self._build_cmd({**self.CMD_OPTS, **cmd_opts})
Expand Down Expand Up @@ -162,16 +163,17 @@ class CrateDBTestAdapter:
CrateDB Toolkit's `DatabaseAdapter`, agnostic of the test framework.
"""

def __init__(self, crate_version: str = "nightly", **kwargs):
def __init__(self, crate_version: str = "nightly", name: str = None, **kwargs):
self.cratedb: Optional[CrateDBContainer] = None
self.database: Optional[DatabaseAdapter] = None
self.image: str = "crate/crate:{}".format(crate_version)
self.name = name

def start(self, **kwargs):
"""
Start testcontainer, used for tests set up
"""
self.cratedb = CrateDBContainer(image=self.image, **kwargs)
self.cratedb = CrateDBContainer(image=self.image, name=self.name, **kwargs)
self.cratedb.start()
self.database = DatabaseAdapter(dburi=self.get_connection_url())

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def cratedb_service():
"""
Provide a CrateDB service instance to the test suite.
"""
db = CrateDBTestAdapter()
db = CrateDBTestAdapter(name="testcontainers-cratedb-custom")
db.start(ports={CRATEDB_HTTP_PORT: None}, cmd_opts=CRATEDB_SETTINGS)
db.reset(tables=RESET_TABLES)
yield db
Expand Down

0 comments on commit 224bba5

Please # to comment.