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

Function test_hc

test/testsam.c:560–618  ·  view source on GitHub ↗

* Test event driven healtchecking. */

Source from the content-addressed store, hash-verified

558 * Test event driven healtchecking.
559 */
560static int test_hc (void)
561{
562 cs_error_t error;
563 unsigned int instance_id;
564 int hc_cb_count;
565
566 printf ("%s: initialize\n", __FUNCTION__);
567 error = sam_initialize (100, SAM_RECOVERY_POLICY_RESTART);
568 if (error != CS_OK) {
569 fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
570 return 1;
571 }
572 printf ("%s: register\n", __FUNCTION__);
573 error = sam_register (&instance_id);
574 if (error != CS_OK) {
575 fprintf (stderr, "Can't register. Error %d\n", error);
576 return 1;
577 }
578
579 if (instance_id == 1) {
580 printf ("%s iid %d: hc callback register\n", __FUNCTION__, instance_id);
581 error = sam_hc_callback_register (test_hc_cb);
582 if (error != CS_OK) {
583 fprintf (stderr, "Can't register hc cb. Error %d\n", error);
584 return 1;
585 }
586
587
588 printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
589 error = sam_start ();
590 if (error != CS_OK) {
591 fprintf (stderr, "Can't start hc. Error %d\n", error);
592 return 1;
593 }
594
595 sleep (2);
596
597 printf ("%s iid %d: Failed. Wasn't killed.\n", __FUNCTION__, instance_id);
598 return 1;
599 }
600
601 if (instance_id == 2) {
602 error = sam_data_restore (&hc_cb_count, sizeof (hc_cb_count));
603 if (error != CS_OK) {
604 fprintf (stderr, "sam_data_restore should return CS_OK. Error returned %d\n", error);
605 return 1;
606 }
607
608 if (hc_cb_count != 11) {
609 fprintf (stderr, "%s iid %d: Premature killed. hc_cb_count should be 11 and it is %d\n",
610 __FUNCTION__, instance_id - 1, hc_cb_count);
611 return 1;
612
613 }
614 return 0;
615 }
616
617 return 1;

Callers

nothing calls this directly

Calls 5

sam_initializeFunction · 0.85
sam_registerFunction · 0.85
sam_hc_callback_registerFunction · 0.85
sam_startFunction · 0.85
sam_data_restoreFunction · 0.85

Tested by

no test coverage detected