| 544 | } |
| 545 | |
| 546 | static void DoTestExpectTimeout(Proxy* p, |
| 547 | const MonoDelta& timeout, |
| 548 | bool will_be_cancelled = false, |
| 549 | bool* is_negotiaton_error = nullptr) { |
| 550 | SleepRequestPB req; |
| 551 | SleepResponsePB resp; |
| 552 | // Sleep for 500ms longer than the call timeout. |
| 553 | int sleep_micros = timeout.ToMicroseconds() + 500 * 1000; |
| 554 | req.set_sleep_micros(sleep_micros); |
| 555 | |
| 556 | RpcController c; |
| 557 | c.set_timeout(timeout); |
| 558 | Stopwatch sw; |
| 559 | sw.start(); |
| 560 | Status s = p->SyncRequest(GenericCalculatorService::kSleepMethodName, req, &resp, &c); |
| 561 | sw.stop(); |
| 562 | ASSERT_FALSE(s.ok()); |
| 563 | if (is_negotiaton_error != nullptr) { |
| 564 | *is_negotiaton_error = c.negotiation_failed(); |
| 565 | } |
| 566 | |
| 567 | int expected_millis = timeout.ToMilliseconds(); |
| 568 | int elapsed_millis = static_cast<int>(sw.elapsed().wall_millis()); |
| 569 | |
| 570 | // We shouldn't timeout significantly faster than our configured timeout, unless the |
| 571 | // rpc is cancelled. |
| 572 | if (!will_be_cancelled) { |
| 573 | EXPECT_GE(elapsed_millis, expected_millis - 10); |
| 574 | } |
| 575 | // And we also shouldn't take the full time that we asked for |
| 576 | EXPECT_LT(elapsed_millis * 1000, sleep_micros); |
| 577 | if (will_be_cancelled) { |
| 578 | // Cancellation is best effort, so even if we cancel the rpc it may still end up |
| 579 | // with a timed out status. |
| 580 | EXPECT_TRUE(s.IsAborted() || s.IsTimedOut()) << s.ToString(); |
| 581 | } else { |
| 582 | EXPECT_TRUE(s.IsTimedOut()) << s.ToString(); |
| 583 | } |
| 584 | LOG(INFO) << "status: " << s.ToString() << ", seconds elapsed: " << sw.elapsed().wall_seconds(); |
| 585 | } |
| 586 | |
| 587 | Status StartTestServer(Sockaddr *server_addr, |
| 588 | bool enable_ssl = false, |
nothing calls this directly
no test coverage detected