From d794b3fddccc71d38d62f04527bb1589f989bcd4 Mon Sep 17 00:00:00 2001 From: Dave Kwon Date: Wed, 21 Sep 2022 12:35:15 -0700 Subject: [PATCH] Make catching exception with finer granularity Summary: Make it finer granularity for better user experience. Reviewed By: AkramaMirza Differential Revision: D39675985 fbshipit-source-id: 4e91c7c6eb6592284afc1aa2a789ec46644dabe1 --- .../src/thrift/conformance/GTestHarness.cpp | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/third-party/thrift/src/thrift/conformance/GTestHarness.cpp b/third-party/thrift/src/thrift/conformance/GTestHarness.cpp index 6d82d07f007c24..17c2bfc590c361 100644 --- a/third-party/thrift/src/thrift/conformance/GTestHarness.cpp +++ b/third-party/thrift/src/thrift/conformance/GTestHarness.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -327,25 +328,40 @@ testing::AssertionResult runRpcTest( Client& client, const RpcTestCase& rpc) { try { client.sync_sendTestCase(rpc); - auto actualClientResult = runClientSteps(client, *rpc.clientInstruction()); - if (!equal(actualClientResult, *rpc.clientTestResult())) { - return testing::AssertionFailure() - << "\nExpected client result: " << jsonify(*rpc.clientTestResult()) - << "\nActual client result: " << jsonify(actualClientResult); - } + } catch (const std::exception& e) { + return testing::AssertionFailure() + << "\nFailed to send RPC test case to server: " << e.what(); + } + + ClientTestResult actualClientResult; + try { + actualClientResult = runClientSteps(client, *rpc.clientInstruction()); + } catch (const std::exception& e) { + return testing::AssertionFailure() + << "\nFailed to receive RPC client result: " << e.what(); + } + + if (!equal(actualClientResult, *rpc.clientTestResult())) { + return testing::AssertionFailure() + << "\nExpected client result: " << jsonify(*rpc.clientTestResult()) + << "\nActual client result: " << jsonify(actualClientResult); + } - // Get result from server - ServerTestResult actualServerResult; + // Get result from server + ServerTestResult actualServerResult; + try { client.sync_getTestResult(actualServerResult); - if (actualServerResult != *rpc.serverTestResult()) { - return testing::AssertionFailure() - << "\nExpected server result: " << jsonify(*rpc.serverTestResult()) - << "\nActual server result: " << jsonify(actualServerResult); - } - return testing::AssertionSuccess(); - } catch (...) { - return testing::AssertionFailure(); + } catch (const std::exception& e) { + return testing::AssertionFailure() + << "\nFailed to receive RPC server result: " << e.what(); } + + if (actualServerResult != *rpc.serverTestResult()) { + return testing::AssertionFailure() + << "\nExpected server result: " << jsonify(*rpc.serverTestResult()) + << "\nActual server result: " << jsonify(actualServerResult); + } + return testing::AssertionSuccess(); } testing::AssertionResult runBasicRpcTest(