From 754ecd758316e2731bf68850807f137badb077da Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Sun, 16 Jun 2024 00:56:47 -0700 Subject: [PATCH] migrate from boost::barrier Summary: Migrate from `boost::barrier` to `std::barrier` and `std::latch`. Reviewed By: Orvid Differential Revision: D58611034 fbshipit-source-id: 5b7483cc7f1fb2f4cae8c5f0c22fe71e1466e543 --- .../test/AcceptRoutingHandlerTest.cpp | 37 ++++++++++--------- wangle/bootstrap/test/BUCK | 4 -- wangle/bootstrap/test/BootstrapTest.cpp | 9 +++-- wangle/bootstrap/test/Mocks.h | 1 - wangle/channel/test/BUCK | 3 -- wangle/channel/test/PipelineTest.cpp | 7 ++-- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/wangle/bootstrap/test/AcceptRoutingHandlerTest.cpp b/wangle/bootstrap/test/AcceptRoutingHandlerTest.cpp index ead0b922e..3d6b16f2f 100644 --- a/wangle/bootstrap/test/AcceptRoutingHandlerTest.cpp +++ b/wangle/bootstrap/test/AcceptRoutingHandlerTest.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "Mocks.h" using namespace folly; @@ -180,7 +182,7 @@ TEST_F(AcceptRoutingHandlerTest, ParseRoutingDataSuccess) { })); // Downstream pipeline is created, and its handler receives events - boost::barrier barrier(2); + std::latch barrier(2); EXPECT_CALL(*downstreamHandler_, transportActive(_)); EXPECT_CALL(*downstreamHandler_, read(_, _)) .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/, @@ -191,14 +193,14 @@ TEST_F(AcceptRoutingHandlerTest, ParseRoutingDataSuccess) { .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* ctx) { VLOG(4) << "Downstream EOF"; ctx->fireClose(); - barrier.wait(); + barrier.arrive_and_wait(); })); EXPECT_CALL(*downstreamHandler_, transportInactive(_)); // Send client request that triggers server processing clientConnectAndCleanClose(); - barrier.wait(); + barrier.arrive_and_wait(); // Routing pipeline has been erased EXPECT_EQ(0, acceptRoutingHandler_->getRoutingPipelineCount()); @@ -206,14 +208,14 @@ TEST_F(AcceptRoutingHandlerTest, ParseRoutingDataSuccess) { TEST_F(AcceptRoutingHandlerTest, SocketErrorInRoutingPipeline) { // Server receives data, and parses routing data - boost::barrier barrierConnect(2); + std::latch barrierConnect(2); EXPECT_CALL(*routingDataHandler_, transportActive(_)); EXPECT_CALL(*routingDataHandler_, parseRoutingData(_, _)) .WillOnce( Invoke([&](folly::IOBufQueue& /*bufQueue*/, MockRoutingDataHandler::RoutingData& /*routingData*/) { VLOG(4) << "Need more data to be parse."; - barrierConnect.wait(); + barrierConnect.arrive_and_wait(); return false; })); @@ -221,8 +223,8 @@ TEST_F(AcceptRoutingHandlerTest, SocketErrorInRoutingPipeline) { auto futureClientPipeline = clientConnectAndWrite(); // Socket exception after routing pipeline had been created - barrierConnect.wait(); - boost::barrier barrierException(2); + barrierConnect.arrive_and_wait(); + std::latch barrierException(2); std::move(futureClientPipeline) .thenValue([](DefaultPipeline* clientPipeline) { clientPipeline->getTransport()->getEventBase()->runInEventBaseThread( @@ -236,9 +238,9 @@ TEST_F(AcceptRoutingHandlerTest, SocketErrorInRoutingPipeline) { folly::exception_wrapper ex) { VLOG(4) << "Routing data handler Exception"; acceptRoutingHandler_->onError(kConnId0, ex); - barrierException.wait(); + barrierException.arrive_and_wait(); })); - barrierException.wait(); + barrierException.arrive_and_wait(); // Downstream pipeline is not created EXPECT_CALL(*downstreamHandler_, transportActive(_)).Times(0); @@ -257,23 +259,24 @@ TEST_F(AcceptRoutingHandlerTest, OnNewConnectionWithBadSocket) { delete downstreamHandler_; // Send client request that triggers server processing - boost::barrier barrierConnect(2); + std::latch barrierConnect(2); EXPECT_CALL(*routingDataHandler_, transportActive(_)) .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/) { - barrierConnect.wait(); + barrierConnect.arrive_and_wait(); })); auto futureClientPipeline = justClientConnect(); - barrierConnect.wait(); + barrierConnect.arrive_and_wait(); futureClientPipeline.wait(); // Expect an exception on the routing data handler - boost::barrier barrierException(2); + std::latch barrierException(2); EXPECT_CALL(*routingDataHandler_, readException(_, _)) - .WillOnce(Invoke( - [&](MockBytesToBytesHandler::Context* /*ctx*/, - folly::exception_wrapper /*ex*/) { barrierException.wait(); })); + .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/, + folly::exception_wrapper /*ex*/) { + barrierException.arrive_and_wait(); + })); sendClientException(futureClientPipeline.value()); - barrierException.wait(); + barrierException.arrive_and_wait(); // Routing pipeline has been added EXPECT_EQ(1, acceptRoutingHandler_->getRoutingPipelineCount()); diff --git a/wangle/bootstrap/test/BUCK b/wangle/bootstrap/test/BUCK index 071e5d3d8..daf7bdd45 100644 --- a/wangle/bootstrap/test/BUCK +++ b/wangle/bootstrap/test/BUCK @@ -25,7 +25,6 @@ cpp_unittest( "//wangle/channel:handler", ], external_deps = [ - ("boost", None, "boost_thread"), "glog", ], ) @@ -43,7 +42,4 @@ cpp_library( "//wangle/channel:pipeline", "//wangle/channel/test:mocks", ], - exported_external_deps = [ - ("boost", None, "boost_thread"), - ], ) diff --git a/wangle/bootstrap/test/BootstrapTest.cpp b/wangle/bootstrap/test/BootstrapTest.cpp index b77c26470..bdaeb988b 100644 --- a/wangle/bootstrap/test/BootstrapTest.cpp +++ b/wangle/bootstrap/test/BootstrapTest.cpp @@ -14,11 +14,12 @@ * limitations under the License. */ +#include + #include "wangle/bootstrap/ClientBootstrap.h" #include "wangle/bootstrap/ServerBootstrap.h" #include "wangle/channel/Handler.h" -#include #include #include #include @@ -166,15 +167,15 @@ TEST(Bootstrap, ServerAcceptGroupTest) { SocketAddress address; server.getSockets()[0]->getAddress(&address); - boost::barrier barrier(2); + std::latch barrier(2); auto thread = std::thread([&]() { TestClient client; client.pipelineFactory(std::make_shared()); client.connect(address); EventBaseManager::get()->getEventBase()->loop(); - barrier.wait(); + barrier.arrive_and_wait(); }); - barrier.wait(); + barrier.arrive_and_wait(); server.stop(); thread.join(); server.join(); diff --git a/wangle/bootstrap/test/Mocks.h b/wangle/bootstrap/test/Mocks.h index 54be3f9de..12335a293 100644 --- a/wangle/bootstrap/test/Mocks.h +++ b/wangle/bootstrap/test/Mocks.h @@ -23,7 +23,6 @@ #include #include -#include #include #include diff --git a/wangle/channel/test/BUCK b/wangle/channel/test/BUCK index cd7c936bd..08057486c 100644 --- a/wangle/channel/test/BUCK +++ b/wangle/channel/test/BUCK @@ -69,7 +69,4 @@ cpp_unittest( "//wangle/channel:pipeline", "//wangle/channel:static_pipeline", ], - external_deps = [ - ("boost", None, "boost_thread"), - ], ) diff --git a/wangle/channel/test/PipelineTest.cpp b/wangle/channel/test/PipelineTest.cpp index 145549e5f..e8fb56a68 100644 --- a/wangle/channel/test/PipelineTest.cpp +++ b/wangle/channel/test/PipelineTest.cpp @@ -14,7 +14,8 @@ * limitations under the License. */ -#include +#include + #include #include #include @@ -372,10 +373,10 @@ TEST(Pipeline, Concurrent) { NiceMock> handler1, handler2; auto pipeline = Pipeline::create(); (*pipeline).addBack(&handler1).addBack(&handler2).finalize(); - boost::barrier b{2}; + std::barrier b{2}; auto spam = [&] { for (int i = 0; i < 100000; i++) { - b.wait(); + b.arrive_and_wait(); pipeline->read(i); } };