-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
import logging | ||
from asyncio import gather | ||
|
||
import pytest | ||
from pytest_operator.plugin import OpsTest | ||
|
||
from .. import markers | ||
from ..helpers import ( | ||
CHARM_SERIES, | ||
) | ||
from .conftest import APPLICATION_NAME | ||
from .helpers import ( | ||
app_name, | ||
are_writes_increasing, | ||
get_primary, | ||
start_continuous_writes, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
charm = None | ||
|
||
|
||
@pytest.mark.group(1) | ||
@markers.juju3 | ||
@pytest.mark.abort_on_fail | ||
async def test_build_and_deploy(ops_test: OpsTest) -> None: | ||
"""Build and deploy two PostgreSQL clusters.""" | ||
# This is a potentially destructive test, so it shouldn't be run against existing clusters | ||
charm = await ops_test.build_charm(".") | ||
async with ops_test.fast_forward(): | ||
# Deploy the first cluster with reusable storage | ||
await gather( | ||
ops_test.model.deploy( | ||
charm, | ||
num_units=2, | ||
series=CHARM_SERIES, | ||
config={"profile": "testing"}, | ||
), | ||
ops_test.model.deploy( | ||
APPLICATION_NAME, | ||
application_name=APPLICATION_NAME, | ||
series=CHARM_SERIES, | ||
channel="edge", | ||
), | ||
) | ||
|
||
await ops_test.model.wait_for_idle(status="active", timeout=1500) | ||
|
||
|
||
@pytest.mark.group(1) | ||
@markers.juju3 | ||
async def test_removing_primary(ops_test: OpsTest, continuous_writes) -> None: | ||
# Start an application that continuously writes data to the database. | ||
app = await app_name(ops_test) | ||
await start_continuous_writes(ops_test, app) | ||
primary = await get_primary(ops_test, app) | ||
await ops_test.model.destroy_unit(primary, force=True, destroy_storage=False, max_wait=1500) | ||
|
||
await ops_test.model.wait_for_idle(status="active", timeout=600) | ||
|
||
await are_writes_increasing(ops_test, primary) |