Skip to content

Commit

Permalink
Make catching exception with finer granularity
Browse files Browse the repository at this point in the history
Summary: Make it finer granularity for better user experience.

Reviewed By: AkramaMirza

Differential Revision: D39675985

fbshipit-source-id: 4e91c7c6eb6592284afc1aa2a789ec46644dabe1
  • Loading branch information
thedavekwon authored and facebook-github-bot committed Sep 21, 2022
1 parent 83c33db commit d794b3f
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions third-party/thrift/src/thrift/conformance/GTestHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <thrift/conformance/GTestHarness.h>

#include <chrono>
#include <exception>
#include <stdexcept>

#include <folly/experimental/coro/AsyncGenerator.h>
Expand Down Expand Up @@ -327,25 +328,40 @@ testing::AssertionResult runRpcTest(
Client<RPCConformanceService>& 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(
Expand Down

0 comments on commit d794b3f

Please sign in to comment.