TensorFlow Serving C++ API Documentation
thread_pool_factory_test.cc
1 /* Copyright 2021 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 
16 #include "tensorflow_serving/servables/tensorflow/thread_pool_factory.h"
17 
18 #include <memory>
19 
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include "tensorflow/core/platform/env.h"
23 #include "tensorflow/core/platform/threadpool.h"
24 #include "tensorflow/core/platform/threadpool_options.h"
25 #include "tensorflow_serving/test_util/test_util.h"
26 
27 namespace tensorflow {
28 namespace serving {
29 namespace {
30 
31 TEST(ScopedThreadPools, DefaultCtor) {
32  ScopedThreadPools thread_pools;
33  EXPECT_EQ(nullptr, thread_pools.get().inter_op_threadpool);
34  EXPECT_EQ(nullptr, thread_pools.get().intra_op_threadpool);
35 }
36 
37 TEST(ScopedThreadPools, NonDefaultCtor) {
38  auto inter_op_thread_pool =
39  std::make_shared<test_util::CountingThreadPool>(Env::Default(), "InterOp",
40  /*num_threads=*/1);
41  auto intra_op_thread_pool =
42  std::make_shared<test_util::CountingThreadPool>(Env::Default(), "InterOp",
43  /*num_threads=*/1);
44  ScopedThreadPools thread_pools(inter_op_thread_pool, intra_op_thread_pool);
45  EXPECT_EQ(inter_op_thread_pool.get(), thread_pools.get().inter_op_threadpool);
46  EXPECT_EQ(intra_op_thread_pool.get(), thread_pools.get().intra_op_threadpool);
47 }
48 
49 } // namespace
50 } // namespace serving
51 } // namespace tensorflow