MCPcopy Create free account
hub / github.com/corosync/corosync / test_cmap_quit

Function test_cmap_quit

test/testsam.c:939–1181  ·  view source on GitHub ↗

* Test cmap integration + quit policy */

Source from the content-addressed store, hash-verified

937 * Test cmap integration + quit policy
938 */
939static int test_cmap_quit (pid_t pid, pid_t old_pid, int test_n)
940{
941 cmap_handle_t cmap_handle;
942 cs_error_t err;
943 uint64_t tstamp1, tstamp2;
944 int32_t msec_diff;
945 unsigned int instance_id;
946 char key_name[CMAP_KEYNAME_MAXLEN];
947 char *str;
948
949 err = cmap_initialize (&cmap_handle);
950 if (err != CS_OK) {
951 printf ("Could not initialize Cluster Map API instance error %d. Test skipped\n", err);
952 return (1);
953 }
954
955 printf ("%s test %d\n", __FUNCTION__, test_n);
956
957 if (test_n == 2) {
958 /*
959 * Object should not exist
960 */
961 printf ("%s Testing if object exists (it shouldn't)\n", __FUNCTION__);
962
963 snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
964 err = cmap_get_string(cmap_handle, key_name, &str);
965 if (err == CS_OK) {
966 printf ("Could find key \"%s\": %d.\n", key_name, err);
967 free(str);
968 return (2);
969 }
970 }
971
972 if (test_n == 1 || test_n == 2) {
973 printf ("%s: initialize\n", __FUNCTION__);
974 err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CMAP);
975 if (err != CS_OK) {
976 fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
977 return 2;
978 }
979
980 printf ("%s: register\n", __FUNCTION__);
981 err = sam_register (&instance_id);
982 if (err != CS_OK) {
983 fprintf (stderr, "Can't register. Error %d\n", err);
984 return 2;
985 }
986
987 snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.recovery", pid);
988 err = cmap_get_string(cmap_handle, key_name, &str);
989 if (err != CS_OK) {
990 printf ("Could not get \"recovery\" key: %d.\n", err);
991 return (2);
992 }
993
994 if (strcmp(str, "quit") != 0) {
995 printf ("Recovery key \"%s\" is not \"quit\".\n", key_name);
996 free(str);

Callers

nothing calls this directly

Calls 8

cmap_initializeFunction · 0.85
cmap_get_stringFunction · 0.85
sam_initializeFunction · 0.85
sam_registerFunction · 0.85
sam_startFunction · 0.85
sam_stopFunction · 0.85
sam_hc_sendFunction · 0.85
cmap_get_uint64Function · 0.85

Tested by

no test coverage detected