forked from lei.chen/myxce
Add libxce cluster discovery and auto-reconnect state machine: - src/include/xce/cluster.h: xce_candidate_t, xce_cluster_config_t, xce_reconnect_ctx_t types; full API with test-seam hook xce_cluster_set_connect_fn() - src/lib/cluster.c: xce_cluster_config_validate() (rejects invalid candidate counts, empty hostname/port, missing identity/ca_cert), xce_connect_cluster() (candidate fallback with single sweep), xce_reconnect_step() state machine (IDLE→CONNECTING→CONNECTED, with exponential backoff; nanosleep skipped when mock is active) - src/lib/meson.build: add cluster.c to libxce_src and test_cluster.c to libxce_test_src (P2.5-2a) - src/lib/testsuite/test_cluster.c: 9 TDD tests covering validation, first-candidate success, fallback, all-fail NULL return, reconnect to CONNECTED, and backoff state transition (P2.5-8) All 9 cluster tests pass; 3 pre-existing unrelated failures unchanged.
140 lines
3.3 KiB
C
140 lines
3.3 KiB
C
#include <argp.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <unity/unity.h>
|
|
|
|
extern void test_xstrings(void);
|
|
extern void test_zarray(void);
|
|
extern void test_ht_string(void);
|
|
extern void test_ht_int(void);
|
|
extern void test_error(void);
|
|
extern void test_utils(void);
|
|
extern void test_config(void);
|
|
extern void test_idgen(void);
|
|
extern void test_preason(void);
|
|
extern void test_ordq(void);
|
|
extern void test_delay(void);
|
|
extern void test_kvmgr(void);
|
|
extern void test_group(void);
|
|
extern void test_xlist(void);
|
|
extern void test_limit(void);
|
|
extern void test_xvec(void);
|
|
extern void test_resreq(void);
|
|
extern void test_select(void);
|
|
extern void test_bitset(void);
|
|
extern void test_kv(void);
|
|
extern void test_jobobj(void);
|
|
extern void test_qobj(void);
|
|
extern void test_wobj(void);
|
|
extern void test_request(void);
|
|
extern void test_zarray_cow(void);
|
|
extern void test_kvmgr_capture(void);
|
|
extern void test_hooks(void);
|
|
extern void test_cluster(void);
|
|
|
|
void setUp(void) { return; }
|
|
|
|
void tearDown(void)
|
|
{
|
|
printf("\n-----------------------------------------------------\n");
|
|
return;
|
|
}
|
|
|
|
static char doc[] = "xcelib_test";
|
|
static char args_doc[] = "";
|
|
|
|
#define MAX_TESTS (256)
|
|
|
|
struct arguments {
|
|
int ntests;
|
|
char* tests[MAX_TESTS];
|
|
};
|
|
|
|
static struct argp_option options[] = {
|
|
{ "run", 't', "STR", 0, "run test" },
|
|
{ 0 }
|
|
};
|
|
|
|
static error_t parse_opt(int key, char* arg, struct argp_state* state)
|
|
{
|
|
struct arguments* arguments = state->input;
|
|
|
|
switch (key) {
|
|
case 't':
|
|
if (arguments->ntests >= MAX_TESTS) {
|
|
fprintf(stderr, "Too many tests\n");
|
|
exit(-1);
|
|
}
|
|
arguments->tests[arguments->ntests] = arg;
|
|
arguments->ntests++;
|
|
break;
|
|
default:
|
|
return ARGP_ERR_UNKNOWN;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct argp argp = { options, parse_opt, args_doc, doc };
|
|
struct arguments arguments;
|
|
|
|
static int check_test(struct arguments* args, char* x)
|
|
{
|
|
int i;
|
|
|
|
if (args->ntests == 0) {
|
|
return 1;
|
|
}
|
|
for (i = 0; i < args->ntests; i++) {
|
|
if (strcmp(x, args->tests[i]) == 0) {
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#define TEST(x) \
|
|
do { \
|
|
if (check_test(&arguments, #x)) { \
|
|
x(); \
|
|
} \
|
|
} while (0)
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
|
|
|
UNITY_BEGIN();
|
|
TEST(test_config);
|
|
TEST(test_idgen);
|
|
TEST(test_ht_string);
|
|
TEST(test_ht_int);
|
|
TEST(test_zarray);
|
|
TEST(test_xstrings);
|
|
TEST(test_error);
|
|
TEST(test_utils);
|
|
TEST(test_preason);
|
|
TEST(test_ordq);
|
|
TEST(test_delay);
|
|
TEST(test_kvmgr);
|
|
TEST(test_group);
|
|
TEST(test_xlist);
|
|
TEST(test_limit);
|
|
TEST(test_xvec);
|
|
TEST(test_resreq);
|
|
TEST(test_select);
|
|
TEST(test_bitset);
|
|
TEST(test_kv);
|
|
TEST(test_jobobj);
|
|
TEST(test_wobj);
|
|
TEST(test_qobj);
|
|
TEST(test_request);
|
|
TEST(test_zarray_cow);
|
|
TEST(test_kvmgr_capture);
|
|
TEST(test_hooks);
|
|
TEST(test_cluster);
|
|
|
|
return UNITY_END();
|
|
}
|