From 9c390e76229d252af762d575110e03e3f844da4f Mon Sep 17 00:00:00 2001 From: Guillaume Bailleul Date: Mon, 20 Mar 2017 15:49:09 +0100 Subject: [PATCH] move to derniercri repo --- README.md | 7 +++---- lib/slap.ex | 12 ++++++++---- lib/slap/reporter.ex | 11 ++++++++++- lib/slap/reporter_cli.ex | 14 +++++--------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d7cea7b..615a45c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Slap -[![Build Status](https://travis-ci.org/laibulle/slap.svg?branch=master)](https://travis-ci.org/laibulle/slap) +[![Build Status](https://travis-ci.org/derniercri/slap.svg?branch=master)](https://travis-ci.org/derniercri/slap) Slap is a load testing tool for developers. @@ -16,9 +16,8 @@ __TODO__ - Parse CLI arguments - Documentation -![Report](https://raw.githubusercontent.com/laibulle/slap/master/doc/bar.png) - -![Plot](https://raw.githubusercontent.com/laibulle/slap/master/doc/plot.png) +![Report](https://raw.githubusercontent.com/derniercri/slap/master/doc/bar.png) +![Plot](https://raw.githubusercontent.com/derniercri/slap/master/doc/plot.png) ## Getting started diff --git a/lib/slap.ex b/lib/slap.ex index c0989c3..3252e49 100644 --- a/lib/slap.ex +++ b/lib/slap.ex @@ -28,7 +28,8 @@ defmodule Slap do # Stop the test Quantum.delete_job(:ticker) - :timer.sleep(3000); # Waiting for requests to finish, assuming it would take at most 3 seconds + GenServer.cast(reporter_id, :stop) + :timer.sleep(3 * 1000) # TODO: should be replaced by someting that wait for all requests to be finished # Run the clean up function Scene.after_run(run_args, data) @@ -40,7 +41,10 @@ defmodule Slap do end def draw_report(reporter_id) do - Slap.ReporterCli.print(GenServer.call(reporter_id, :compute)) + case GenServer.call reporter_id, :running do + true -> Slap.ReporterCli.print(GenServer.call(reporter_id, :compute)) + false -> -1 + end :timer.sleep(1000); draw_report(reporter_id) end @@ -65,10 +69,10 @@ defmodule Slap do {:ok, script} = File.read scene # Parse the script file {:ok, reporter_id} = init # Start a GenServer to handle the data report spawn(fn -> draw_report(reporter_id) end) - report = run(duration, clients, script, custom_args, reporter_id) + report = run(duration, clients, script, custom_args, reporter_id) + Slap.ReporterCli.print report # Print report into HTML Slap.ReporterHTML.print report # Print report into HTML IO.puts "\nYou can open an HTML report with `open report.html`" - _ -> IO.puts "Invalid arguments\n Exemple: slap examples/scene1.exs 10 10 --custom_arg1 32" end end diff --git a/lib/slap/reporter.ex b/lib/slap/reporter.ex index 1fe708b..d9d7721 100644 --- a/lib/slap/reporter.ex +++ b/lib/slap/reporter.ex @@ -12,7 +12,8 @@ defmodule Slap.Reporter do average_latency: 0, total_time: 0, total_iterations: 0, - current_iteration: 0 + current_iteration: 0, + running: true }} end @@ -20,6 +21,10 @@ defmodule Slap.Reporter do {:noreply, concat(metrics, state)} end + def handle_cast(:stop, state) do + {:noreply, %{state | running: false}} + end + def handle_cast({:set_iterations, iterations}, state) do {:noreply, %{state | total_iterations: iterations}} end @@ -45,6 +50,10 @@ defmodule Slap.Reporter do state end + def handle_call(:running, _from, state) do + {:reply, state.running, state} + end + def handle_call(:compute, _from, state) do {:reply, compute(state), state} end diff --git a/lib/slap/reporter_cli.ex b/lib/slap/reporter_cli.ex index f6b75c7..f494569 100644 --- a/lib/slap/reporter_cli.ex +++ b/lib/slap/reporter_cli.ex @@ -14,19 +14,15 @@ defmodule Slap.ReporterCli do if report.total_iterations > 0 do IO.write "\e[1A" - ProgressBar.render(report.current_iteration, report.total_iterations, format) - IO.write "\n" + IO.write "\r" + clean(80) + IO.write "\r" write(report) + IO.write "\n" + ProgressBar.render(report.current_iteration, report.total_iterations, format) end end - def print(report) do - IO.write "\r" - clean(80) - IO.write "\r" - write(report) - end - def clean(0) do end