TensorFlow Serving C++ API Documentation
prediction_service_grpc_test.cc
1 /* Copyright 2020 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #include "tensorflow_serving/experimental/tensorflow/ops/remote_predict/kernels/prediction_service_grpc.h"
16 
17 #include <memory>
18 
19 #include "absl/time/clock.h"
20 #include "tensorflow/core/framework/tensor_testutil.h"
21 
22 namespace tensorflow {
23 namespace serving {
24 namespace {
25 
26 class PredictionServiceGrpcTest : public ::testing::Test {
27  protected:
28  virtual void SetUp() {
29  auto prediction_service_status =
30  PredictionServiceGrpc::Create("target_address", &grpc_stub_);
31  }
32  std::unique_ptr<PredictionServiceGrpc> grpc_stub_;
33  std::unique_ptr<::grpc::ClientContext> rpc_;
34 };
35 
36 TEST_F(PredictionServiceGrpcTest, TestSetDeadline) {
37  const absl::Duration deadline = absl::Milliseconds(30000);
38  auto rpc_or = grpc_stub_->CreateRpc(deadline);
39  ASSERT_TRUE(rpc_or.ok());
40  rpc_.reset(rpc_or.value());
41 
42  EXPECT_NEAR(absl::ToDoubleMilliseconds(deadline),
43  absl::ToDoubleMilliseconds(absl::FromChrono(rpc_->deadline()) -
44  absl::Now()),
45  10);
46 }
47 
48 } // namespace
49 } // namespace serving
50 } // namespace tensorflow