From 93c4556ce0afe417bf15c02ab7047ebf4aaa9854 Mon Sep 17 00:00:00 2001 From: Vasu Dasari Date: Thu, 2 Jul 2020 14:03:56 -0400 Subject: [PATCH] grpcbox-ct: Stress test grpcbox Added a stress_test to stress number of concurrent gRPC sessions that can be run. BY default it is set to 10. But can be modified by environment variable GRPCBOX_STRESS_TEST # To run 25 concurrent sessions: $ GRPCBOX_STRESS_TEST=25 rebar3 ct --suite grpcbox_SUITE --case stress_test On my system, it above command breaks around 30-35. Signed-off-by: Vasu Dasari --- test/grpcbox_SUITE.erl | 40 +++++++++++++++++++++++++++++++++ test/routeguide_route_guide.erl | 4 ---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/test/grpcbox_SUITE.erl b/test/grpcbox_SUITE.erl index 0eab414..0465523 100644 --- a/test/grpcbox_SUITE.erl +++ b/test/grpcbox_SUITE.erl @@ -28,6 +28,7 @@ all() -> chain_interceptor, stream_interceptor, bidirectional, + stress_test, client_stream, compression, stats_handler, @@ -189,6 +190,15 @@ init_per_testcase(bidirectional, Config) -> services => #{'routeguide.RouteGuide' => routeguide_route_guide}}}]), application:ensure_all_started(grpcbox), Config; +init_per_testcase(stress_test, Config) -> + application:load(grpcbox), + application:set_env(grpcbox, client, #{channels => [{default_channel, + [{http, "localhost", 8080, []}], #{}}]}), + application:set_env(grpcbox, servers, + [#{grpc_opts => #{service_protos => [route_guide_pb], + services => #{'routeguide.RouteGuide' => routeguide_route_guide}}}]), + application:ensure_all_started(grpcbox), + Config; init_per_testcase(client_stream, Config) -> application:set_env(grpcbox, client, #{channels => [{default_channel, [{http, "localhost", 8080, []}], #{}}]}), @@ -520,6 +530,36 @@ stream_interceptor(_Config) -> ?assertMatch({ok, #{name := <<"Louvre">>}}, grpcbox_client:recv_data(Stream)), ?assertMatch({ok, {_, _, #{<<"x-grpc-stream-interceptor">> := <<"true">>}}}, grpcbox_client:recv_trailers(Stream)). +stress_test_function(Fun, Config, Ref, Parent) -> + Parent ! {stress_test, Ref, Fun(Config)}. + +stress_test(Config) -> + stress_test(Config, + erlang:list_to_integer( + os:getenv("GRPCBOX_STRESS_TEST", "10") + )). + +stress_test(Config, Count) -> + lists:foreach(fun + (Ref) -> + Parent = self(), + spawn(fun() -> + stress_test_function(fun bidirectional/1, Config, Ref, Parent) end) + end, lists:seq(1, Count)), + + Loop = fun Loop(LoopCount) -> + receive + {stress_test, _Ref, _Reply} when LoopCount < Count -> + Loop(LoopCount + 1); + {stress_test, _Ref, _Reply} when LoopCount < Count -> + LoopCount + 1 + after + 2000 -> + LoopCount + end + end, + ?assertEqual(Count, Loop(0)). + %% cert_dir(Config) -> diff --git a/test/routeguide_route_guide.erl b/test/routeguide_route_guide.erl index e6e8ede..d3a27b1 100644 --- a/test/routeguide_route_guide.erl +++ b/test/routeguide_route_guide.erl @@ -19,10 +19,6 @@ #{lo => point(), hi => point()}. --type route_note() :: - #{location => point(), - message => string()}. - -type feature() :: #{name => string(), location => point()}.