diff options
author | yang-g <yangg@google.com> | 2015-12-10 15:35:34 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-12-10 15:35:34 -0800 |
commit | e682c3eea4bb9370467501893bdce78a95ecdbbf (patch) | |
tree | 237de3d92b9b02a7eb8756f7a3d5ebd5dc4f13a8 /test/core/surface | |
parent | e73499782a562dde0d0ac3244845de4c0f2c574f (diff) |
add test for lame client transport op
Diffstat (limited to 'test/core/surface')
-rw-r--r-- | test/core/surface/lame_client_test.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index fd57dd02f9..ba94d14290 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -36,11 +36,47 @@ #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include "src/core/channel/channel_stack.h" +#include "src/core/iomgr/closure.h" +#include "src/core/surface/channel.h" +#include "src/core/transport/transport.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/util/test_config.h" +grpc_closure transport_op_cb; + static void *tag(gpr_intptr x) { return (void *)x; } +void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, int success) { + grpc_transport_op* op = arg; + GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state); + GPR_ASSERT(success); +} + +void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) { } + +void test_transport_op(grpc_channel *channel) { + grpc_transport_op op; + grpc_channel_element *elem; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + memset(&op, 0, sizeof(op)); + grpc_closure_init(&transport_op_cb, verify_connectivity, &op); + + op.on_connectivity_state_change = &transport_op_cb; + op.connectivity_state = &state; + elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); + elem->filter->start_transport_op(&exec_ctx, elem, &op); + grpc_exec_ctx_finish(&exec_ctx); + + memset(&op, 0, sizeof(op)); + grpc_closure_init(&transport_op_cb, do_nothing, NULL); + op.on_consumed = &transport_op_cb; + elem->filter->start_transport_op(&exec_ctx, elem, &op); + grpc_exec_ctx_finish(&exec_ctx); +} + int main(int argc, char **argv) { grpc_channel *chan; grpc_call *call; @@ -65,6 +101,9 @@ int main(int argc, char **argv) { chan = grpc_lame_client_channel_create( "lampoon:national", GRPC_STATUS_UNKNOWN, "Rpc sent on a lame channel."); GPR_ASSERT(chan); + + test_transport_op(chan); + cq = grpc_completion_queue_create(NULL); call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, |