worker.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <signal.h>
  19. #include <chrono>
  20. #include <thread>
  21. #include <vector>
  22. #include "absl/flags/flag.h"
  23. #include <grpc/grpc.h>
  24. #include <grpc/support/time.h>
  25. #include "test/core/util/test_config.h"
  26. #include "test/cpp/qps/qps_worker.h"
  27. #include "test/cpp/util/test_config.h"
  28. #include "test/cpp/util/test_credentials_provider.h"
  29. ABSL_FLAG(int32_t, driver_port, 0, "Port for communication with driver");
  30. ABSL_FLAG(int32_t, server_port, 0,
  31. "Port for operation as a server, if not specified by the server "
  32. "config message");
  33. ABSL_FLAG(std::string, credential_type, grpc::testing::kInsecureCredentialsType,
  34. "Credential type for communication with driver");
  35. static bool got_sigint = false;
  36. static void sigint_handler(int /*x*/) { got_sigint = true; }
  37. namespace grpc {
  38. namespace testing {
  39. std::vector<grpc::testing::Server*>* g_inproc_servers = nullptr;
  40. static void RunServer() {
  41. QpsWorker worker(absl::GetFlag(FLAGS_driver_port),
  42. absl::GetFlag(FLAGS_server_port),
  43. absl::GetFlag(FLAGS_credential_type));
  44. while (!got_sigint && !worker.Done()) {
  45. gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
  46. gpr_time_from_millis(500, GPR_TIMESPAN)));
  47. }
  48. }
  49. } // namespace testing
  50. } // namespace grpc
  51. int main(int argc, char** argv) {
  52. grpc::testing::TestEnvironment env(argc, argv);
  53. grpc::testing::InitTest(&argc, &argv, true);
  54. signal(SIGINT, sigint_handler);
  55. grpc::testing::RunServer();
  56. return 0;
  57. }