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/support/log.h>
22
23 #include "src/core/lib/iomgr/endpoint_pair.h"
24 #include "src/core/lib/iomgr/iomgr.h"
25 #include "test/core/util/test_config.h"
26
main(int argc,char ** argv)27 int main(int argc, char** argv) {
28 int i;
29 struct rlimit rlim;
30 grpc_endpoint_pair p;
31
32 grpc_test_init(argc, argv);
33 grpc_init();
34 {
35 grpc_core::ExecCtx exec_ctx;
36
37 /* set max # of file descriptors to a low value, and
38 verify we can create and destroy many more than this number
39 of descriptors */
40 rlim.rlim_cur = rlim.rlim_max = 10;
41 GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim));
42 grpc_resource_quota* resource_quota =
43 grpc_resource_quota_create("fd_conservation_posix_test");
44
45 for (i = 0; i < 100; i++) {
46 p = grpc_iomgr_create_endpoint_pair("test", nullptr);
47 grpc_endpoint_destroy(p.client);
48 grpc_endpoint_destroy(p.server);
49 grpc_core::ExecCtx::Get()->Flush();
50 }
51
52 grpc_resource_quota_unref(resource_quota);
53 }
54
55 grpc_shutdown();
56 return 0;
57 }
58