/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include class TestHandler : public apache::thrift::ServiceHandler { folly::coro::Task co_func() override { co_return; } }; CO_TEST(AsyncClientTest, ZeroDependency) { class TestEventHandler : public apache::thrift::TProcessorEventHandler { void preRead(void* /*ctx*/, const char* /*fn_name*/) override { preReadCallCount++; } void postWrite( void* /*ctx*/, const char* /*fn_name*/, uint32_t /*bytes*/) override { postWriteCallCount++; } public: int preReadCallCount = 0; int postWriteCallCount = 0; }; auto eventHandler = std::make_shared(); apache::thrift::TClientBase::addClientEventHandler(eventHandler); SCOPE_EXIT { apache::thrift::TClientBase::removeClientEventHandler(eventHandler); }; using ClientType = apache::thrift::Client; std::unique_ptr client = apache::thrift::makeTestClient(std::make_shared()); std::unique_ptr zeroDepClient = std::make_unique( client->getChannelShared(), ClientType::Options::zeroDependency()); co_await zeroDepClient->co_func(); EXPECT_EQ(eventHandler->preReadCallCount, 0); EXPECT_EQ(eventHandler->postWriteCallCount, 0); co_await client->co_func(); EXPECT_EQ(eventHandler->preReadCallCount, 1); EXPECT_EQ(eventHandler->postWriteCallCount, 1); }