Merge lp:~clint-fewbar/gearmand/fix-connection-failover into lp:gearmand/1.0

Proposed by Clint Byrum
Status: Merged
Merged at revision: 377
Proposed branch: lp:~clint-fewbar/gearmand/fix-connection-failover
Merge into: lp:gearmand/1.0
Diff against target: 76 lines (+37/-6)
2 files modified
libgearman/connection.c (+6/-6)
tests/worker_test.c (+31/-0)
To merge this branch: bzr merge lp:~clint-fewbar/gearmand/fix-connection-failover
Reviewer Review Type Date Requested Status
Brian Aker Needs Information
Review via email: mp+47438@code.launchpad.net

Description of the change

Fixes order of operations when errors happen to allow proper failover to other servers during CONNECT phase.

To post a comment you must log in.
Revision history for this message
Brian Aker (brianaker) wrote :

Why comment out these lines?

 + //gearman_return_t ret= gearman_worker_echo(cloned, "test", sizeof("test"));
62 +
63 + //test_truth(ret == GEARMAN_SUCCESS);

review: Needs Information
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Oops sorry Brian for the slow response. I initially wrote the test to do an echo, but that wasn't actually testing the same code path (its more client-like than worker-like). Forgot to remove these two lines. I just pushed up a change which does just that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libgearman/connection.c'
--- libgearman/connection.c 2010-04-04 21:27:36 +0000
+++ libgearman/connection.c 2011-02-15 20:28:17 +0000
@@ -553,17 +553,17 @@
553 case GEARMAN_CON_UNIVERSAL_CONNECTING:553 case GEARMAN_CON_UNIVERSAL_CONNECTING:
554 while (1)554 while (1)
555 {555 {
556 if (connection->revents & POLLOUT)556 if (connection->revents & (POLLERR | POLLHUP | POLLNVAL))
557 {
558 connection->state= GEARMAN_CON_UNIVERSAL_CONNECTED;
559 break;
560 }
561 else if (connection->revents & (POLLERR | POLLHUP | POLLNVAL))
562 {557 {
563 connection->state= GEARMAN_CON_UNIVERSAL_CONNECT;558 connection->state= GEARMAN_CON_UNIVERSAL_CONNECT;
564 connection->addrinfo_next= connection->addrinfo_next->ai_next;559 connection->addrinfo_next= connection->addrinfo_next->ai_next;
565 break;560 break;
566 }561 }
562 else if (connection->revents & POLLOUT)
563 {
564 connection->state= GEARMAN_CON_UNIVERSAL_CONNECTED;
565 break;
566 }
567567
568 gret= gearman_connection_set_events(connection, POLLOUT);568 gret= gearman_connection_set_events(connection, POLLOUT);
569 if (gret != GEARMAN_SUCCESS)569 if (gret != GEARMAN_SUCCESS)
570570
=== modified file 'tests/worker_test.c'
--- tests/worker_test.c 2010-06-30 10:49:39 +0000
+++ tests/worker_test.c 2011-02-15 20:28:17 +0000
@@ -629,6 +629,36 @@
629 return TEST_SUCCESS;629 return TEST_SUCCESS;
630}630}
631631
632static test_return_t gearman_worker_failover_test(void *object)
633{
634 gearman_worker_st *worker= (gearman_worker_st *)object;
635 gearman_worker_st *cloned;
636 gearman_return_t rc;
637 const char *function_name= "_gearman_worker_add_function_worker_fn";
638
639 cloned= gearman_worker_clone(NULL, worker);
640 gearman_worker_add_server(cloned, NULL, WORKER_TEST_PORT);
641 gearman_worker_add_server(cloned, NULL, WORKER_TEST_PORT+1);
642
643 rc= gearman_worker_add_function(cloned,
644 function_name,
645 0, _gearman_worker_add_function_worker_fn, NULL);
646 test_truth(rc == GEARMAN_SUCCESS);
647
648 gearman_worker_set_timeout(cloned, 2);
649
650 rc= gearman_worker_work(cloned);
651 test_truth(rc == GEARMAN_TIMEOUT);
652
653 /* Make sure we have remove worker function */
654 rc= gearman_worker_unregister(cloned, function_name);
655 test_truth(rc == GEARMAN_SUCCESS);
656
657 gearman_worker_free(cloned);
658
659 return TEST_SUCCESS;
660}
661
632/*********************** World functions **************************************/662/*********************** World functions **************************************/
633663
634void *create(void *object __attribute__((unused)))664void *create(void *object __attribute__((unused)))
@@ -695,6 +725,7 @@
695 {"gearman_worker_unregister_all", 0, gearman_worker_unregister_all_test },725 {"gearman_worker_unregister_all", 0, gearman_worker_unregister_all_test },
696 {"gearman_worker_work with timout", 0, gearman_worker_work_with_test },726 {"gearman_worker_work with timout", 0, gearman_worker_work_with_test },
697 {"gearman_worker_context", 0, gearman_worker_context_test },727 {"gearman_worker_context", 0, gearman_worker_context_test },
728 {"gearman_worker_failover", 0, gearman_worker_failover_test },
698 {"echo_max", 0, echo_max_test },729 {"echo_max", 0, echo_max_test },
699 {"abandoned_worker", 0, abandoned_worker_test },730 {"abandoned_worker", 0, abandoned_worker_test },
700 {0, 0, 0}731 {0, 0, 0}

Subscribers

People subscribed via source and target branches