@@ -799,6 +799,33 @@ def test_check_stanza(harness):
799
799
assert _update_config .call_count == 2
800
800
assert _member_started .call_count == 5
801
801
assert _reload_patroni_configuration .call_count == 5
802
+ assert harness .get_relation_data (peer_rel_id , harness .charm .app ) == {
803
+ "stanza" : "test-stanza" ,
804
+ "init-pgbackrest" : "True" ,
805
+ }
806
+ assert harness .get_relation_data (peer_rel_id , harness .charm .unit ) == {}
807
+ assert isinstance (harness .charm .unit .status , BlockedStatus )
808
+ assert harness .charm .unit .status .message == FAILED_TO_INITIALIZE_STANZA_ERROR_MESSAGE
809
+
810
+ # Test when the archiving is not working correctly (pgBackRest check command fails) on leader.
811
+ with harness .hooks_disabled ():
812
+ harness .set_leader (True )
813
+ harness .update_relation_data (
814
+ peer_rel_id ,
815
+ harness .charm .app .name ,
816
+ {"stanza" : "test-stanza" , "init-pgbackrest" : "True" },
817
+ )
818
+ harness .update_relation_data (
819
+ peer_rel_id ,
820
+ harness .charm .unit .name ,
821
+ {"stanza" : "test-stanza" , "init-pgbackrest" : "True" },
822
+ )
823
+ _execute_command .side_effect = ExecError (
824
+ command = stanza_check_command , exit_code = 1 , stdout = "" , stderr = "fake error"
825
+ )
826
+ _member_started .return_value = True
827
+ harness .charm .backup .check_stanza ()
828
+ assert _update_config .call_count == 4
802
829
assert harness .get_relation_data (peer_rel_id , harness .charm .app ) == {}
803
830
assert harness .get_relation_data (peer_rel_id , harness .charm .unit ) == {}
804
831
assert isinstance (harness .charm .unit .status , BlockedStatus )
@@ -807,6 +834,7 @@ def test_check_stanza(harness):
807
834
# Test when the archiving is working correctly (pgBackRest check command succeeds)
808
835
# and the unit is not the leader.
809
836
with harness .hooks_disabled ():
837
+ harness .set_leader (False )
810
838
harness .update_relation_data (
811
839
peer_rel_id ,
812
840
harness .charm .app .name ,
0 commit comments