From bab043e8650799b91a4e40853e56439c2ddb15a7 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 16 Nov 2018 15:27:13 -0800 Subject: Cleanup --- test/core/transport/chttp2/context_list_test.cc | 39 +++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'test/core/transport') diff --git a/test/core/transport/chttp2/context_list_test.cc b/test/core/transport/chttp2/context_list_test.cc index 1f7a38a107..3814184e16 100644 --- a/test/core/transport/chttp2/context_list_test.cc +++ b/test/core/transport/chttp2/context_list_test.cc @@ -18,12 +18,17 @@ #include "src/core/lib/iomgr/port.h" +#include +#include + +#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/context_list.h" +#include "src/core/lib/transport/transport.h" +#include "test/core/util/mock_endpoint.h" +#include "test/core/util/test_config.h" #include -#include "test/core/util/test_config.h" - static void TestExecuteFlushesListVerifier(void* arg, grpc_core::Timestamps* ts) { GPR_ASSERT(arg != nullptr); @@ -31,6 +36,8 @@ static void TestExecuteFlushesListVerifier(void* arg, gpr_atm_rel_store(done, static_cast(1)); } +static void discard_write(grpc_slice slice) {} + /** Tests that all ContextList elements in the list are flushed out on * execute. * Also tests that arg is passed correctly. @@ -39,19 +46,41 @@ static void TestExecuteFlushesList() { grpc_core::ContextList* list = nullptr; grpc_http2_set_write_timestamps_callback(TestExecuteFlushesListVerifier); #define NUM_ELEM 5 - grpc_chttp2_stream s[NUM_ELEM]; + grpc_core::ExecCtx exec_ctx; + grpc_stream_refcount ref; + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("context_list_test"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_transport* t = + grpc_create_chttp2_transport(nullptr, mock_endpoint, true); + std::vector s; + s.reserve(NUM_ELEM); gpr_atm verifier_called[NUM_ELEM]; for (auto i = 0; i < NUM_ELEM; i++) { - s[i].context = &verifier_called[i]; + s.push_back(static_cast( + gpr_malloc(grpc_transport_stream_size(t)))); + grpc_transport_init_stream(reinterpret_cast(t), + reinterpret_cast(s[i]), &ref, + nullptr, nullptr); + s[i]->context = &verifier_called[i]; gpr_atm_rel_store(&verifier_called[i], static_cast(0)); - grpc_core::ContextList::Append(&list, &s[i]); + grpc_core::ContextList::Append(&list, s[i]); } grpc_core::Timestamps ts; grpc_core::ContextList::Execute(list, &ts, GRPC_ERROR_NONE); for (auto i = 0; i < NUM_ELEM; i++) { GPR_ASSERT(gpr_atm_acq_load(&verifier_called[i]) == static_cast(1)); + grpc_transport_destroy_stream(reinterpret_cast(t), + reinterpret_cast(s[i]), + nullptr); + exec_ctx.Flush(); + gpr_free(s[i]); } + grpc_transport_destroy(t); + grpc_resource_quota_unref(resource_quota); + exec_ctx.Flush(); } static void TestContextList() { TestExecuteFlushesList(); } -- cgit v1.2.3