Remove optional parameter from watch connectivity state

pull/2751/head
Craig Tiller 9 years ago
parent 909917955c
commit 2cd9dd9da6
  1. 8
      include/grpc/grpc.h
  2. 8
      src/core/surface/channel_connectivity.c
  3. 22
      test/core/end2end/tests/channel_connectivity.c

@ -414,14 +414,10 @@ grpc_connectivity_state grpc_channel_check_connectivity_state(
Once the channel connectivity state is different from last_observed_state,
tag will be enqueued on cq with success=1.
If deadline expires BEFORE the state is changed, tag will be enqueued on cq
with success=0.
If optional_new_state is non-NULL, it will be set to the newly observed
connectivity state of the channel at the same point as tag is enqueued onto
the completion queue. */
with success=0. */
void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
grpc_connectivity_state *optional_new_state, gpr_timespec deadline,
grpc_completion_queue *cq, void *tag);
gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
/** Create a call given a grpc_channel, in order to call 'method'. All
completions are sent to 'completion_queue'. 'method' and 'host' need only

@ -70,7 +70,6 @@ typedef struct {
grpc_iomgr_closure on_complete;
grpc_alarm alarm;
grpc_connectivity_state state;
grpc_connectivity_state *optional_new_state;
grpc_completion_queue *cq;
grpc_cq_completion completion_storage;
grpc_channel *channel;
@ -124,9 +123,6 @@ static void partly_done(state_watcher *w, int due_to_completion) {
switch (w->phase) {
case WAITING:
w->phase = CALLING_BACK;
if (w->optional_new_state) {
*w->optional_new_state = w->state;
}
grpc_cq_end_op(w->cq, w->tag, w->success, finished_completion, w,
&w->completion_storage);
break;
@ -154,8 +150,7 @@ static void timeout_complete(void *pw, int success) { partly_done(pw, 0); }
void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
grpc_connectivity_state *optional_new_state, gpr_timespec deadline,
grpc_completion_queue *cq, void *tag) {
gpr_timespec deadline, grpc_completion_queue *cq, void *tag) {
grpc_channel_element *client_channel_elem =
grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel));
state_watcher *w = gpr_malloc(sizeof(*w));
@ -167,7 +162,6 @@ void grpc_channel_watch_connectivity_state(
w->phase = WAITING;
w->state = last_observed_state;
w->success = 0;
w->optional_new_state = optional_new_state;
w->cq = cq;
w->tag = tag;
w->channel = channel;

@ -54,7 +54,7 @@ static void test_connectivity(grpc_end2end_test_config config) {
/* start watching for a change */
grpc_channel_watch_connectivity_state(
f.client, GRPC_CHANNEL_IDLE, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(1));
f.client, GRPC_CHANNEL_IDLE, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(1));
/* nothing should happen */
cq_verify_empty(cqv);
@ -64,14 +64,17 @@ static void test_connectivity(grpc_end2end_test_config config) {
/* and now the watch should trigger */
cq_expect_completion(cqv, tag(1), 1);
cq_verify(cqv);
state = grpc_channel_check_connectivity_state(f.client, 0);
GPR_ASSERT(state == GRPC_CHANNEL_CONNECTING);
/* quickly followed by a transition to TRANSIENT_FAILURE */
grpc_channel_watch_connectivity_state(
f.client, GRPC_CHANNEL_CONNECTING, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(2));
f.client, GRPC_CHANNEL_CONNECTING, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(2));
cq_expect_completion(cqv, tag(2), 1);
cq_verify(cqv);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE);
state = grpc_channel_check_connectivity_state(f.client, 0);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
state == GRPC_CHANNEL_CONNECTING);
gpr_log(GPR_DEBUG, "*** STARTING SERVER ***");
@ -84,10 +87,13 @@ static void test_connectivity(grpc_end2end_test_config config) {
READY is reached */
while (state != GRPC_CHANNEL_READY) {
grpc_channel_watch_connectivity_state(
f.client, state, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(3));
f.client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(3));
cq_expect_completion(cqv, tag(3), 1);
cq_verify(cqv);
GPR_ASSERT(state == GRPC_CHANNEL_READY || state == GRPC_CHANNEL_CONNECTING || state == GRPC_CHANNEL_TRANSIENT_FAILURE);
state = grpc_channel_check_connectivity_state(f.client, 0);
GPR_ASSERT(state == GRPC_CHANNEL_READY ||
state == GRPC_CHANNEL_CONNECTING ||
state == GRPC_CHANNEL_TRANSIENT_FAILURE);
}
/* bring down the server again */
@ -95,14 +101,16 @@ static void test_connectivity(grpc_end2end_test_config config) {
gpr_log(GPR_DEBUG, "*** SHUTTING DOWN SERVER ***");
grpc_channel_watch_connectivity_state(
f.client, GRPC_CHANNEL_READY, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(4));
f.client, GRPC_CHANNEL_READY, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(4));
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
cq_expect_completion(cqv, tag(4), 1);
cq_expect_completion(cqv, tag(0xdead), 1);
cq_verify(cqv);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE);
state = grpc_channel_check_connectivity_state(f.client, 0);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
state == GRPC_CHANNEL_CONNECTING);
/* cleanup server */
grpc_server_destroy(f.server);

Loading…
Cancel
Save