소스 검색

TEST: Use pacemaker repeat macro

This is to simulate the way pacemaker uses the cpg api.
With this you can run testcpg directly after corosync
starts and it should initialise ok.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Angus Salkeld 14 년 전
부모
커밋
0379faca4e
1개의 변경된 파일35개의 추가작업 그리고 7개의 파일을 삭제
  1. 35 7
      test/testcpg.c

+ 35 - 7
test/testcpg.c

@@ -165,11 +165,36 @@ static void sigintr_handler (int signum) {
 }
 }
 static struct cpg_name group_name;
 static struct cpg_name group_name;
 
 
+
+#define cs_repeat_init(counter, max, code) do {    \
+	code;                                 \
+	if (result == CS_ERR_TRY_AGAIN || result == CS_ERR_QUEUE_FULL || result == CS_ERR_LIBRARY) {  \
+		counter++;                    \
+		printf("Retrying operation after %ds\n", counter); \
+		sleep(counter);               \
+	} else {                              \
+		break;                        \
+	}                                     \
+} while (counter < max)
+
+#define cs_repeat(counter, max, code) do {    \
+	code;                                 \
+	if (result == CS_ERR_TRY_AGAIN || result == CS_ERR_QUEUE_FULL) {  \
+		counter++;                    \
+		printf("Retrying operation after %ds\n", counter); \
+		sleep(counter);               \
+	} else {                              \
+		break;                        \
+	}                                     \
+} while (counter < max)
+
+
 int main (int argc, char *argv[]) {
 int main (int argc, char *argv[]) {
 	cpg_handle_t handle;
 	cpg_handle_t handle;
 	fd_set read_fds;
 	fd_set read_fds;
 	int select_fd;
 	int select_fd;
 	int result;
 	int result;
+	int retries;
 	const char *options = "i";
 	const char *options = "i";
 	int opt;
 	int opt;
 	unsigned int nodeid;
 	unsigned int nodeid;
@@ -195,27 +220,30 @@ int main (int argc, char *argv[]) {
 		group_name.length = 6;
 		group_name.length = 6;
 	}
 	}
 
 
-	result = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model_data, NULL);
+	retries = 0;
+	cs_repeat_init(retries, 30, result = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model_data, NULL));
 	if (result != CS_OK) {
 	if (result != CS_OK) {
 		printf ("Could not initialize Cluster Process Group API instance error %d\n", result);
 		printf ("Could not initialize Cluster Process Group API instance error %d\n", result);
 		exit (1);
 		exit (1);
 	}
 	}
-	result = cpg_local_get (handle, &nodeid);
+	retries = 0;
+	cs_repeat(retries, 30, result = cpg_local_get(handle, &nodeid));
 	if (result != CS_OK) {
 	if (result != CS_OK) {
 		printf ("Could not get local node id\n");
 		printf ("Could not get local node id\n");
 		exit (1);
 		exit (1);
 	}
 	}
-
 	printf ("Local node id is %x\n", nodeid);
 	printf ("Local node id is %x\n", nodeid);
-	result = cpg_join(handle, &group_name);
+
+	retries = 0;
+	cs_repeat(retries, 30, result = cpg_join(handle, &group_name));
 	if (result != CS_OK) {
 	if (result != CS_OK) {
 		printf ("Could not join process group, error %d\n", result);
 		printf ("Could not join process group, error %d\n", result);
 		exit (1);
 		exit (1);
 	}
 	}
 
 
-	sleep (1);
-	result = cpg_membership_get (handle, &group_name,
-		(struct cpg_address *)&member_list, &member_list_entries);
+	retries = 0;
+	cs_repeat(retries, 30, result = cpg_membership_get (handle, &group_name,
+		(struct cpg_address *)&member_list, &member_list_entries));
 	if (result != CS_OK) {
 	if (result != CS_OK) {
 		printf ("Could not get current membership list %d\n", result);
 		printf ("Could not get current membership list %d\n", result);
 		exit (1);
 		exit (1);