test_proxy_timeout.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 
  2. #include "hello_test.h"
  3. //#include "util/tc_socket_async.h"
  4. TEST_F(HelloTest, proxyInvokeTimeout)
  5. {
  6. shared_ptr<Communicator> c = getCommunicator();
  7. transGlobalCommunicator([&](Communicator *comm){
  8. checkSyncTimeout(comm);
  9. }, c.get());
  10. transInCoroutineGlobalCommunicator([&](Communicator *comm){
  11. checkSyncTimeout(comm);
  12. }, c.get());
  13. transServerCommunicator([&](Communicator *comm){
  14. checkSyncTimeout(comm);
  15. });
  16. transInCoroutineServerCommunicator([&](Communicator *comm){
  17. checkSyncTimeout(comm);
  18. });
  19. transAllocCommunicator([&](Communicator *comm){
  20. checkSyncTimeout(comm);
  21. });
  22. transInCoroutineAllocCommunicator([&](Communicator *comm){
  23. checkSyncTimeout(comm);
  24. });
  25. }
  26. TEST_F(HelloTest, proxyAsyncInvokeTimeout)
  27. {
  28. shared_ptr<Communicator> c = getCommunicator();
  29. transGlobalCommunicator([&](Communicator *comm){
  30. checkASyncTimeout(comm);
  31. }, c.get());
  32. transInCoroutineGlobalCommunicator([&](Communicator *comm){
  33. checkASyncTimeout(comm);
  34. }, c.get());
  35. transServerCommunicator([&](Communicator *comm){
  36. checkASyncTimeout(comm);
  37. });
  38. transInCoroutineServerCommunicator([&](Communicator *comm){
  39. checkASyncTimeout(comm);
  40. });
  41. transAllocCommunicator([&](Communicator *comm){
  42. checkASyncTimeout(comm);
  43. });
  44. transInCoroutineAllocCommunicator([&](Communicator *comm){
  45. checkASyncTimeout(comm);
  46. });
  47. }
  48. TEST_F(HelloTest, proxyConnectionTimeout)
  49. {
  50. shared_ptr<Communicator> c = getCommunicator();
  51. HelloPrx prx = c->stringToProxy<HelloPrx>("TestApp.HelloServer.HelloObj@tcp -h 111.111.111.11 -p 4444");
  52. prx->tars_connect_timeout(5000);
  53. prx->tars_set_timeout(20000);
  54. prx->tars_async_timeout(30000);
  55. int64_t t = TNOWMS;
  56. bool connectError = false;
  57. try
  58. {
  59. string out;
  60. prx->testHello(0, "test", out);
  61. }
  62. catch(exception &ex)
  63. {
  64. connectError = true;
  65. }
  66. ASSERT_TRUE(connectError);
  67. LOG_CONSOLE_DEBUG << TNOWMS - t << endl;
  68. ASSERT_TRUE(TNOWMS - t >= 5000 && TNOWMS - t < 5050);
  69. }