Skip to content

Commit a576119

Browse files
committed
Increase update status interval
1 parent a7a7551 commit a576119

File tree

1 file changed

+68
-65
lines changed

1 file changed

+68
-65
lines changed

tests/integration/test_tls.py

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -113,76 +113,79 @@ async def test_tls_enabled(ops_test: OpsTest) -> None:
113113
# Pause Patroni so it doesn't wipe the custom changes
114114
await change_patroni_setting(ops_test, "pause", True, use_random_unit=True, tls=True)
115115

116-
for attempt in Retrying(
117-
stop=stop_after_delay(60 * 5), wait=wait_exponential(multiplier=1, min=2, max=30)
118-
):
119-
with attempt:
120-
# Promote the replica to primary.
121-
await run_command_on_unit(
122-
ops_test,
123-
replica,
124-
"sudo -u snap_daemon charmed-postgresql.pg-ctl -D /var/snap/charmed-postgresql/common/var/lib/postgresql/ promote",
125-
)
126-
127-
# Check that the replica was promoted.
128-
host = get_unit_address(ops_test, replica)
129-
password = await get_password(ops_test, replica)
130-
with db_connect(host, password) as connection:
131-
connection.autocommit = True
132-
with connection.cursor() as cursor:
133-
cursor.execute("SELECT pg_is_in_recovery();")
134-
in_recovery = cursor.fetchone()[0]
135-
print(f"in_recovery: {in_recovery}")
136-
assert not in_recovery
137-
connection.close()
138-
139-
# Write some data to the initial primary (this causes a divergence
140-
# in the instances' timelines).
141-
host = get_unit_address(ops_test, primary)
142-
password = await get_password(ops_test, primary)
143-
with db_connect(host, password) as connection:
144-
connection.autocommit = True
145-
with connection.cursor() as cursor:
146-
cursor.execute("CREATE TABLE IF NOT EXISTS pgrewindtest (testcol INT);")
147-
cursor.execute("INSERT INTO pgrewindtest SELECT generate_series(1,1000);")
148-
connection.close()
149-
150-
# Stop the initial primary by killing both Patroni and PostgreSQL OS processes.
151-
await run_command_on_unit(
152-
ops_test,
153-
primary,
154-
"pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/14/bin/postgres",
155-
)
156-
await run_command_on_unit(
157-
ops_test,
158-
primary,
159-
"pkill --signal SIGKILL -f /snap/charmed-postgresql/[0-9]*/usr/bin/patroni",
160-
)
116+
async with ops_test.fast_forward("20m"):
117+
for attempt in Retrying(
118+
stop=stop_after_delay(60 * 5), wait=wait_exponential(multiplier=1, min=2, max=30)
119+
):
120+
with attempt:
121+
# Promote the replica to primary.
122+
await run_command_on_unit(
123+
ops_test,
124+
replica,
125+
"sudo -u snap_daemon charmed-postgresql.pg-ctl -D /var/snap/charmed-postgresql/common/var/lib/postgresql/ promote",
126+
)
127+
128+
# Check that the replica was promoted.
129+
host = get_unit_address(ops_test, replica)
130+
password = await get_password(ops_test, replica)
131+
with db_connect(host, password) as connection:
132+
connection.autocommit = True
133+
with connection.cursor() as cursor:
134+
cursor.execute("SELECT pg_is_in_recovery();")
135+
in_recovery = cursor.fetchone()[0]
136+
print(f"in_recovery: {in_recovery}")
137+
assert not in_recovery
138+
connection.close()
139+
140+
# Write some data to the initial primary (this causes a divergence
141+
# in the instances' timelines).
142+
host = get_unit_address(ops_test, primary)
143+
password = await get_password(ops_test, primary)
144+
with db_connect(host, password) as connection:
145+
connection.autocommit = True
146+
with connection.cursor() as cursor:
147+
cursor.execute("CREATE TABLE IF NOT EXISTS pgrewindtest (testcol INT);")
148+
cursor.execute("INSERT INTO pgrewindtest SELECT generate_series(1,1000);")
149+
connection.close()
150+
151+
# Stop the initial primary by killing both Patroni and PostgreSQL OS processes.
152+
await run_command_on_unit(
153+
ops_test,
154+
primary,
155+
"pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/14/bin/postgres",
156+
)
157+
await run_command_on_unit(
158+
ops_test,
159+
primary,
160+
"pkill --signal SIGKILL -f /snap/charmed-postgresql/[0-9]*/usr/bin/patroni",
161+
)
161162

162-
# Check that the primary changed.
163-
assert await primary_changed(ops_test, primary), "primary not changed"
164-
change_primary_start_timeout(ops_test, primary, 300)
163+
# Check that the primary changed.
164+
assert await primary_changed(ops_test, primary), "primary not changed"
165+
change_primary_start_timeout(ops_test, primary, 300)
165166

166-
# Check the logs to ensure TLS is being used by pg_rewind.
167-
primary = await get_primary(ops_test, primary)
168-
await run_command_on_unit(
169-
ops_test,
170-
primary,
171-
"grep 'connection authorized: user=rewind database=postgres SSL enabled' /var/snap/charmed-postgresql/common/var/log/postgresql/postgresql-*.log",
172-
)
167+
# Check the logs to ensure TLS is being used by pg_rewind.
168+
primary = await get_primary(ops_test, primary)
169+
await run_command_on_unit(
170+
ops_test,
171+
primary,
172+
"grep 'connection authorized: user=rewind database=postgres SSL enabled' /var/snap/charmed-postgresql/common/var/log/postgresql/postgresql-*.log",
173+
)
173174

174-
await change_patroni_setting(ops_test, "pause", False, use_random_unit=True, tls=True)
175+
await change_patroni_setting(ops_test, "pause", False, use_random_unit=True, tls=True)
175176

176-
# Remove the relation.
177-
await ops_test.model.applications[DATABASE_APP_NAME].remove_relation(
178-
f"{DATABASE_APP_NAME}:certificates", f"{tls_certificates_app_name}:certificates"
179-
)
180-
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000)
177+
# Remove the relation.
178+
await ops_test.model.applications[DATABASE_APP_NAME].remove_relation(
179+
f"{DATABASE_APP_NAME}:certificates", f"{tls_certificates_app_name}:certificates"
180+
)
181+
await ops_test.model.wait_for_idle(
182+
apps=[DATABASE_APP_NAME], status="active", timeout=1000
183+
)
181184

182-
# Wait for all units disabling TLS.
183-
for unit in ops_test.model.applications[DATABASE_APP_NAME].units:
184-
assert await check_tls(ops_test, unit.name, enabled=False)
185-
assert await check_tls_patroni_api(ops_test, unit.name, enabled=False)
185+
# Wait for all units disabling TLS.
186+
for unit in ops_test.model.applications[DATABASE_APP_NAME].units:
187+
assert await check_tls(ops_test, unit.name, enabled=False)
188+
assert await check_tls_patroni_api(ops_test, unit.name, enabled=False)
186189

187190

188191
@pytest.mark.group(1)

0 commit comments

Comments
 (0)