55 * LICENSE file in the root directory of this source tree.
66 */
77
8+ #include < fstream>
9+ #include < stdexcept>
810#include < string>
911
1012#include < gtest/gtest.h>
@@ -869,6 +871,9 @@ TEST(AsyncMcClient, caretVersionUserSpecified) {
869871}
870872
871873TEST (AsyncMcClient, caretAdditionalFields) {
874+ #ifdef LIBMC_FBTRACE_DISABLE
875+ GTEST_SKIP () << " Tracing is disabled in the OSS build" ;
876+ #endif
872877 TestServer::Config config;
873878 config.useSsl = false ;
874879 auto server = TestServer::create (std::move (config));
@@ -958,6 +963,26 @@ using TFOTestParams = std::tuple<bool, bool, bool, SecurityMech>;
958963
959964class AsyncMcClientTFOTest : public TestWithParam <TFOTestParams> {};
960965
966+ /* *
967+ * Check whether the current host system supports TCP fastopen.
968+ */
969+ bool tfoSupportedOnHost () {
970+ try {
971+ constexpr int kClientSupport = 1 ;
972+ constexpr int kDataInOpeningSynWithoutCookie = 4 ;
973+ int flags;
974+ std::ifstream procFs (" /proc/sys/net/ipv4/tcp_fastopen" );
975+ procFs >> flags;
976+
977+ return
978+ (flags & kClientSupport ) == kClientSupport &&
979+ (flags & kDataInOpeningSynWithoutCookie ) == kDataInOpeningSynWithoutCookie ;
980+ } catch (std::exception& e) {
981+ LOG (ERROR) << " Could not read TCP fastopen sysctl: " << e.what ();
982+ return false ;
983+ }
984+ }
985+
961986TEST_P (AsyncMcClientTFOTest, testTfoWithSSL) {
962987 auto serverEnabled = std::get<0 >(GetParam ());
963988 auto clientEnabled = std::get<1 >(GetParam ());
@@ -971,9 +996,10 @@ TEST_P(AsyncMcClientTFOTest, testTfoWithSSL) {
971996
972997 auto offloadHandshake = std::get<2 >(GetParam ());
973998 auto constexpr nConnAttempts = 10 ;
999+ auto tfoSupported = tfoSupportedOnHost ();
9741000
9751001 auto mech = std::get<3 >(GetParam ());
976- auto sendReq = [serverEnabled, clientEnabled, mech](TestClient& client) {
1002+ auto sendReq = [serverEnabled, clientEnabled, tfoSupported, mech](TestClient& client) {
9771003 client.setConnectionStatusCallbacks (
9781004 [&](const folly::AsyncTransportWrapper& sock, int64_t ) {
9791005 if (mech == SecurityMech::TLS_TO_PLAINTEXT) {
@@ -982,10 +1008,16 @@ TEST_P(AsyncMcClientTFOTest, testTfoWithSSL) {
9821008 auto stats = socket->getStats ();
9831009 if (clientEnabled) {
9841010 EXPECT_TRUE (stats.tfoAttempted );
985- EXPECT_TRUE (stats.tfoFinished );
986- // we can not guarantee socket->getTFOSucceeded() will return true
987- // unless there are specific kernel + host settings applied
988- if (!serverEnabled) {
1011+
1012+ if (tfoSupported) {
1013+ EXPECT_TRUE (stats.tfoFinished );
1014+ if (serverEnabled) {
1015+ EXPECT_TRUE (stats.tfoSuccess );
1016+ } else {
1017+ EXPECT_FALSE (stats.tfoSuccess );
1018+ }
1019+ } else {
1020+ EXPECT_FALSE (stats.tfoFinished );
9891021 EXPECT_FALSE (stats.tfoSuccess );
9901022 }
9911023 } else {
@@ -995,10 +1027,16 @@ TEST_P(AsyncMcClientTFOTest, testTfoWithSSL) {
9951027 auto * socket = sock.getUnderlyingTransport <folly::AsyncSocket>();
9961028 if (clientEnabled) {
9971029 EXPECT_TRUE (socket->getTFOAttempted ());
998- EXPECT_TRUE (socket->getTFOFinished ());
999- // we can not guarantee socket->getTFOSucceeded() will return true
1000- // unless there are specific kernel + host settings applied
1001- if (!serverEnabled) {
1030+
1031+ if (tfoSupported) {
1032+ EXPECT_TRUE (socket->getTFOFinished ());
1033+ if (serverEnabled) {
1034+ EXPECT_TRUE (socket->getTFOSucceded ());
1035+ } else {
1036+ EXPECT_FALSE (socket->getTFOSucceded ());
1037+ }
1038+ } else {
1039+ EXPECT_FALSE (socket->getTFOFinished ());
10021040 EXPECT_FALSE (socket->getTFOSucceded ());
10031041 }
10041042 } else {
@@ -1143,6 +1181,9 @@ TEST_P(AsyncMcClientSSLOffloadTest, closeNow) {
11431181 EXPECT_FALSE (upCalled);
11441182 EXPECT_TRUE (downReason.has_value ());
11451183 EXPECT_EQ (*downReason, ConnectionDownReason::ABORTED);
1184+
1185+ server->shutdown ();
1186+ server->join ();
11461187}
11471188
11481189TEST_P (AsyncMcClientSSLOffloadTest, clientReset) {
@@ -1164,6 +1205,9 @@ TEST_P(AsyncMcClientSSLOffloadTest, clientReset) {
11641205 evb.loopOnce ();
11651206 client.reset ();
11661207 evb.loop ();
1208+
1209+ server->shutdown ();
1210+ server->join ();
11671211}
11681212
11691213INSTANTIATE_TEST_CASE_P (AsyncMcClientTest, AsyncMcClientSSLOffloadTest, Bool());
0 commit comments