fd_conservation_posix_test.cc 1.5 KB

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