Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Scenario.WS.PingPong do
- use Chaperon.Scenario
- def init(session) do
- # We can add custom session setup logic in an `init/1` function, if we need to.
- # Returns {:ok, session} or {:error, reason} (see `Chaperon.Session` module)
- session
- |> ws_connect("/socket.io/?EIO=3&transport=websocket")
- |> ok
- end
- def run(session) do
- # Accessing config values using the `Session.config/2` helper function.
- # Alternatively we could have just accessed `session.config.ping_pong.iterations`
- # but using the helper function as we do here gives us better error messages
- # in case we didn't define the config value for this session.
- iterations = session |> config([:ping_pong, :iterations])
- # This will call `ping_pong/1` repeatedly for `iterations` amount of times
- # and record the duration of calling it in a histogram
- :timer.sleep(5000);
- session
- |> repeat_traced(:ping_pong, iterations)
- |> log_info("PingPong finished after #{iterations} iterations")
- end
- def ping_pong(session) do
- session
- |> ws_send("42[\"xxx\",\"true\"]")
- |> ws_await_recv(~r/^(.*)zzz(.*)$/)
- end
- def teardown(session) do
- # We can also define a `teardown/1` function which then gets called with our
- # session after we successfully ran our `run/1` defined above.
- # This is useful for cleaning up resources or performing other logic after
- # we've run our load test scenario.
- # Note that any actions in this code will not be traced and no metrics for
- # them will be recorded in the final metrics histogram output.
- session
- |> ws_close
- end
- end
- defmodule LoadTest.PingPong do
- use Chaperon.LoadTest
- def default_config, do: %{
- base_url: "ws://127.0.0.1:3456"
- }
- # run 100 PingPong sessions (each with 10 iterations) across the cluster
- # `scenario/0` is expected to return a list of 2-tuples (`{scenario_module, config}`)
- # for each load test.
- # `scenario_module` can be `{concurrency, scenario_module}` if running multiple
- # concurrent instances of the scenario is needed
- def scenarios, do: [
- {{1, Scenario.WS.PingPong}, %{
- ping_pong: %{
- iterations: 10
- }
- }}
- ]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement