feat(ha-config-bootstrap): implement bootstrap_config_if_needed() (task 5.3)
- Probe all peers: any tag>0 -> defer_config_fetch=true; all-zero -> proceed; none reachable -> exponential backoff 500ms->10s cap with WARN per attempt - Wire into myapp.c: before ha_wait_for_heartbeat_or_timeout() - Post-election: defer_config_fetch && CTRL_STANDBY -> fetch_config_from_primary() - INFO log for all three bootstrap outcomes (Req 10.2) - XCE_TESTING hook for probe mock; test_ha_bootstrap_support.c installs mock - 9/9 bootstrap tests GREEN, 141/141 full suite GREEN
This commit is contained in:
parent
0c4a0760d1
commit
ab174c8b06
6 changed files with 163 additions and 8 deletions
41
src/controller/testsuite/test_ha_bootstrap_support.c
Normal file
41
src/controller/testsuite/test_ha_bootstrap_support.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* test_ha_bootstrap_support.c — Test fixture for bootstrap probe injection.
|
||||
*
|
||||
* This file is compiled into the controller_unit_test binary under XCE_TESTING.
|
||||
* It installs a mock probe function via __attribute__((constructor)) before any
|
||||
* test runs, so that test_ha_bootstrap.c tests do not need real network peers.
|
||||
*
|
||||
* Mock probe behaviour (keyed by port):
|
||||
* port 59901 → tag = 0xDEAD0001 (non-zero: peer has a config)
|
||||
* port 59902 → tag = 0 (zero: peer has no config)
|
||||
* port 59900 → tag = 0 (zero: peer has no config)
|
||||
* any other → tag = 0 (zero: treat as unconfigured)
|
||||
*
|
||||
* Requirements: 3.2 (any peer tag>0 → defer), 3.3 (all-zero → no defer)
|
||||
*/
|
||||
#ifdef XCE_TESTING
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config_repl.h"
|
||||
|
||||
static int mock_xce_probe_config_tag(const char *host, uint16_t port,
|
||||
uint64_t *tag_out)
|
||||
{
|
||||
(void)host;
|
||||
/* Port 59901: simulate a peer that already has a config (non-zero tag) */
|
||||
if (port == 59901) {
|
||||
*tag_out = 0xDEAD000100000001ULL;
|
||||
return 0;
|
||||
}
|
||||
/* All other test ports return tag=0 (unconfigured peer) */
|
||||
*tag_out = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void install_bootstrap_probe_mock(void)
|
||||
{
|
||||
xce_probe_config_tag_hook = mock_xce_probe_config_tag;
|
||||
}
|
||||
|
||||
#endif /* XCE_TESTING */
|
||||
Loading…
Add table
Add a link
Reference in a new issue