1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include <sys/resource.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/support/log.h>
23
24 #include "src/core/lib/gprpp/crash.h"
25 #include "src/core/lib/iomgr/endpoint_pair.h"
26 #include "src/core/lib/iomgr/iomgr.h"
27 #include "test/core/util/test_config.h"
28
main(int argc,char ** argv)29 int main(int argc, char** argv) {
30 int i;
31 struct rlimit rlim;
32 grpc_endpoint_pair p;
33
34 grpc::testing::TestEnvironment env(&argc, argv);
35 grpc_init();
36 {
37 grpc_core::ExecCtx exec_ctx;
38
39 // set max # of file descriptors to a low value, and
40 // verify we can create and destroy many more than this number
41 // of descriptors
42 rlim.rlim_cur = rlim.rlim_max = 1000;
43 GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim));
44 for (i = 0; i < 10000; i++) {
45 p = grpc_iomgr_create_endpoint_pair("test", nullptr);
46 grpc_endpoint_destroy(p.client);
47 grpc_endpoint_destroy(p.server);
48 grpc_core::ExecCtx::Get()->Flush();
49 }
50 }
51
52 grpc_shutdown();
53 return 0;
54 }
55