• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  *
4  * Copyright 2019 gRPC authors.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
20 #include "src/core/lib/iomgr/poller/eventmanager_libuv.h"
21 
22 #include <grpc/grpc.h>
23 #include <grpc/support/time.h>
24 #include <gtest/gtest.h>
25 
26 #include "test/core/util/test_config.h"
27 
28 using grpc::experimental::LibuvEventManager;
29 
30 namespace grpc_core {
31 namespace {
32 
TEST(LibuvEventManager,Allocation)33 TEST(LibuvEventManager, Allocation) {
34   for (int i = 0; i < 10; i++) {
35     LibuvEventManager* em = new LibuvEventManager(i);
36     gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1));
37     delete em;
38   }
39 }
40 
TEST(LibuvEventManager,ShutdownRef)41 TEST(LibuvEventManager, ShutdownRef) {
42   for (int i = 0; i < 10; i++) {
43     LibuvEventManager* em = new LibuvEventManager(i);
44     for (int j = 0; j < i; j++) {
45       em->ShutdownRef();
46     }
47     gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1));
48     for (int j = 0; j < i; j++) {
49       em->ShutdownUnref();
50     }
51     delete em;
52   }
53 }
54 
TEST(LibuvEventManager,ShutdownRefAsync)55 TEST(LibuvEventManager, ShutdownRefAsync) {
56   for (int i = 0; i < 10; i++) {
57     LibuvEventManager* em = new LibuvEventManager(i);
58     for (int j = 0; j < i; j++) {
59       em->ShutdownRef();
60     }
61     grpc_core::Thread deleter(
62         "deleter", [](void* em) { delete static_cast<LibuvEventManager*>(em); },
63         em);
64     deleter.Start();
65     gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1));
66     for (int j = 0; j < i; j++) {
67       em->ShutdownUnref();
68     }
69     deleter.Join();
70   }
71 }
72 
73 }  // namespace
74 }  // namespace grpc_core
75 
main(int argc,char ** argv)76 int main(int argc, char** argv) {
77   grpc_init();
78   grpc::testing::TestEnvironment env(argc, argv);
79   ::testing::InitGoogleTest(&argc, argv);
80   int retval = RUN_ALL_TESTS();
81   grpc_shutdown();
82   return retval;
83 }
84