Skip to content

Commit

Permalink
int tests + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Dec 1, 2023
1 parent a5fcb79 commit c14490f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
22 changes: 22 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from charms.mongodb.v1.helpers import MONGO_SHELL
from pytest_operator.plugin import OpsTest
import ops

MONGOS_URI = (
"mongodb://%2Fvar%2Fsnap%2Fcharmed-mongodb%2Fcommon%2Fvar%2Fmongodb-27018.sock"
)
MONGOS_APP_NAME = "mongos"


async def mongs_command(ops_test: OpsTest) -> str:
"""Generates a command which verifies TLS status."""
return f"{MONGO_SHELL} '{MONGOS_URI}' --eval 'use test-db'"


async def check_mongos(ops_test: OpsTest, unit: ops.model.Unit) -> bool:
"""Returns whether mongos is running on the provided unit."""
mongos_check = await mongs_command(ops_test)
check_tls_cmd = f"exec --unit {unit.name} -- {mongos_check}"
return_code, _, _ = await ops_test.juju(*check_tls_cmd.split())
mongos_running = return_code == 0
return mongos_running
48 changes: 44 additions & 4 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
# See LICENSE file for licensing details.
import pytest
from pytest_operator.plugin import OpsTest
from .helpers import check_mongos

APPLICATION_APP_NAME = "application"
MONGOS_APP_NAME = "mongos"
CLUSTER_REL_NAME = "cluster"

CONFIG_SERVER_APP_NAME = "config-server"
SHARD_APP_NAME = "shard"
SHARD_REL_NAME = "sharding"
CONFIG_SERVER_REL_NAME = "config-server"


@pytest.mark.abort_on_fail
Expand Down Expand Up @@ -45,8 +52,41 @@ async def test_waits_for_config_server(ops_test: OpsTest) -> None:
idle_period=10,
),

config_server_unit = ops_test.model.applications[MONGOS_APP_NAME].units[0]
assert (
config_server_unit.workload_status_message
== "Missing relation to config-server."
mongos_unit = ops_test.model.applications[MONGOS_APP_NAME].units[0]
assert mongos_unit.workload_status_message == "Missing relation to config-server."


@pytest.mark.abort_on_fail
# wait for 6/edge charm on mongodb to be updated before running this test on CI
@pytest.mark.skip()
async def test_mongos_starts_with_config_server(ops_test: OpsTest) -> None:
# prepare sharded cluster
await ops_test.model.wait_for_idle(
apps=[CONFIG_SERVER_APP_NAME, SHARD_APP_NAME],
idle_period=10,
raise_on_blocked=False,
)
await ops_test.model.integrate(
f"{SHARD_APP_NAME}:{SHARD_REL_NAME}",
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}",
)
await ops_test.model.wait_for_idle(
apps=[CONFIG_SERVER_APP_NAME, SHARD_APP_NAME],
idle_period=10,
raise_on_blocked=False,
)

# connect sharded cluster to mongos
await ops_test.model.integrate(
f"{MONGOS_APP_NAME}:{CLUSTER_REL_NAME}",
f"{CONFIG_SERVER_APP_NAME}:{CLUSTER_REL_NAME}",
)
await ops_test.model.wait_for_idle(
apps=[CONFIG_SERVER_APP_NAME, SHARD_APP_NAME, MONGOS_APP_NAME],
idle_period=10,
status="active",
)

mongos_unit = ops_test.model.applications[MONGOS_APP_NAME].units[0]
mongos_running = await check_mongos(ops_test, mongos_unit)
assert mongos_running, "Mongos is not currently running."

0 comments on commit c14490f

Please sign in to comment.