Skip to content

Commit e502ff0

Browse files
Fix upgrade changed event executing too early (#217)
1 parent 88a5cbf commit e502ff0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/upgrade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _on_postgresql_pebble_ready(self, event: WorkloadEvent) -> None:
115115

116116
def _on_upgrade_changed(self, _) -> None:
117117
"""Update the Patroni nosync tag in the unit if needed."""
118-
if not self.peer_relation:
118+
if not self.peer_relation or not self.charm._patroni.member_started:
119119
return
120120

121121
self.charm.update_config()

tests/unit/test_upgrade.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@ def test_on_postgresql_pebble_ready(
149149
_set_unit_failed.assert_not_called()
150150

151151
@patch("charm.PostgresqlOperatorCharm.update_config")
152-
def test_on_upgrade_changed(self, _update_config):
152+
@patch("charm.Patroni.member_started", new_callable=PropertyMock)
153+
def test_on_upgrade_changed(self, _member_started, _update_config):
154+
_member_started.return_value = False
153155
relation = self.harness.model.get_relation("upgrade")
154156
self.charm.on.upgrade_relation_changed.emit(relation)
157+
_update_config.assert_not_called()
158+
159+
_member_started.return_value = True
160+
self.charm.on.upgrade_relation_changed.emit(relation)
155161
_update_config.assert_called_once()
156162

157163
@patch("charm.PostgreSQLUpgrade._set_rolling_update_partition")

0 commit comments

Comments
 (0)