-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 781d08a
Showing
53 changed files
with
1,287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
|
||
[{!*.md,!*.markdown}] | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
api_example/deps | ||
|
||
/slap | ||
report.html | ||
.DS_Store | ||
|
||
*.zip | ||
*.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: elixir | ||
elixir: | ||
- 1.4 | ||
otp_release: | ||
- 18.2.1 | ||
script: | ||
- mix test | ||
- mix escript.build | ||
deploy: | ||
provider: releases | ||
skip_cleanup: true | ||
api_key: | ||
secure: L6QWceDiVkuXCwv3g6crVYp6vxScmT0Sm4EJL4z5HKc6UMDPFspNeeA5tMAXk0plJPkliS+W189cZALDok9fH1dIkGcx4WY4vbxLJ0lXVEEWstYGNOZsMj22sDoIRp+3P9IdInAtStcRyr9TCiODtOw68TkdSUMUyqbIHGA+VLZKnzK5wAniueCFjI1vU+Q6leddLIGQFbpL7TVt+ptIW3x9olfK0Fpq5j7ENpVV8kvaVPKoBFeIMZLi6IpylH5avHgVK4KY8TbbhStuvGFQwymLGb6HJSYDQLZSJuiOfkEQH4v17s0Stt3vzzoHVgZxIAkshqZelII5bZ2AVw16Deu+6ywlWTPyOQmSRZQ6qQioABWu9JqoAu+6hQytlqzTfBaf85ajBlsPnEORGMnsPQACcJZEvGvxxAVG5bL9bndqPownZ0fqBVpZVjxWzc7UABgBHnHUGS/KfMBZwLGgu2r4y7EEzatfVejl3Z0CExapDMmPuMir622eje1Zwr1dqfA9/vYz1HhEe35IpjkBb+a+w9LVh7qE5vwgO/cIAUMTgqi0dLt5xfZs50QWvhBhm1iBsQiIvKiMbeT17maoKxDXpx6Co1uDA65hlM1LDGYJJ9BflIlTAPDq2WaRyjrOek7LVxzNYgpxomxEYtnx0KS8PNTUgX+ZMnSrD858B7g= | ||
file: slap | ||
on: | ||
repo: laibulle/slap | ||
branch: travis | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Slap | ||
|
||
[![Build Status](https://travis-ci.org/laibulle/slap.svg?branch=master)](https://travis-ci.org/laibulle/slap) | ||
|
||
Slap is a load testing tool for developers. | ||
|
||
__Features__ | ||
|
||
- Real time reporting | ||
- Script scenario with Elixir | ||
|
||
__TODO__ | ||
|
||
- Distribute between several OTP instances | ||
- Integrate script dependencies | ||
- 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) | ||
|
||
|
||
## Getting started | ||
|
||
First of all you have to start the fake server that will handle the traffic. | ||
|
||
``` | ||
cd examples/api | ||
mix deps.get | ||
mix phoenix.server | ||
``` | ||
|
||
Build Slap with the following command | ||
```bash | ||
mix escript.build && chmod +x slap | ||
``` | ||
|
||
Now you can run the example scenario with the Slap binary. | ||
``` | ||
slap examples/scene1.exs | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file is responsible for configuring your application | ||
# and its dependencies with the aid of the Mix.Config module. | ||
use Mix.Config | ||
|
||
# This configuration is loaded before any dependency and is restricted | ||
# to this project. If another project depends on this project, this | ||
# file won't be loaded nor affect the parent project. For this reason, | ||
# if you want to provide default values for your application for | ||
# 3rd-party users, it should be done in your "mix.exs" file. | ||
|
||
# You can configure for your application as: | ||
# | ||
# config :slap, key: :value | ||
# | ||
# And access this configuration in your application as: | ||
# | ||
# Application.get_env(:slap, :key) | ||
# | ||
# Or configure a 3rd-party app: | ||
# | ||
# config :logger, level: :info | ||
# | ||
|
||
# It is also possible to import configuration files, relative to this | ||
# directory. For example, you can emulate configuration per environment | ||
# by uncommenting the line below and defining dev.exs, test.exs and such. | ||
# Configuration from the imported file will override the ones defined | ||
# here (which is why it is important to import them last). | ||
# | ||
# import_config "#{Mix.env}.exs" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# App artifacts | ||
/_build | ||
/db | ||
/deps | ||
/*.ez | ||
|
||
# Generated on crash by the VM | ||
erl_crash.dump | ||
|
||
# The config/prod.secret.exs file by default contains sensitive | ||
# data and you should not commit it into version control. | ||
# | ||
# Alternatively, you may comment the line below and commit the | ||
# secrets file as long as you replace its contents by environment | ||
# variables. | ||
/config/prod.secret.exs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# ApiExample | ||
|
||
To start your Phoenix app: | ||
|
||
* Install dependencies with `mix deps.get` | ||
* Start Phoenix endpoint with `mix phoenix.server` | ||
|
||
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. | ||
|
||
Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment). | ||
|
||
## Learn more | ||
|
||
* Official website: http://www.phoenixframework.org/ | ||
* Guides: http://phoenixframework.org/docs/overview | ||
* Docs: https://hexdocs.pm/phoenix | ||
* Mailing list: http://groups.google.com/group/phoenix-talk | ||
* Source: https://github.com/phoenixframework/phoenix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is responsible for configuring your application | ||
# and its dependencies with the aid of the Mix.Config module. | ||
# | ||
# This configuration file is loaded before any dependency and | ||
# is restricted to this project. | ||
use Mix.Config | ||
|
||
# Configures the endpoint | ||
config :api_example, ApiExample.Endpoint, | ||
url: [host: "localhost"], | ||
secret_key_base: "9bNtISoZVA86Ihjmz116clpFR/bY0zvBqDBrISgwuHditIEZyN7bS/DVOl3TA2ll", | ||
render_errors: [view: ApiExample.ErrorView, accepts: ~w(html json)], | ||
pubsub: [name: ApiExample.PubSub, | ||
adapter: Phoenix.PubSub.PG2] | ||
|
||
# Configures Elixir's Logger | ||
config :logger, :console, | ||
format: "$time $metadata[$level] $message\n", | ||
metadata: [:request_id] | ||
|
||
# Import environment specific config. This must remain at the bottom | ||
# of this file so it overrides the configuration defined above. | ||
import_config "#{Mix.env}.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use Mix.Config | ||
|
||
# For development, we disable any cache and enable | ||
# debugging and code reloading. | ||
# | ||
# The watchers configuration can be used to run external | ||
# watchers to your application. For example, we use it | ||
# with brunch.io to recompile .js and .css sources. | ||
config :api_example, ApiExample.Endpoint, | ||
http: [port: 4000], | ||
debug_errors: true, | ||
code_reloader: true, | ||
check_origin: false, | ||
watchers: [] | ||
|
||
|
||
# Watch static and templates for browser reloading. | ||
config :api_example, ApiExample.Endpoint, | ||
live_reload: [ | ||
patterns: [ | ||
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, | ||
~r{priv/gettext/.*(po)$}, | ||
~r{web/views/.*(ex)$}, | ||
~r{web/templates/.*(eex)$} | ||
] | ||
] | ||
|
||
# Do not include metadata nor timestamps in development logs | ||
config :logger, :console, format: "[$level] $message\n" | ||
|
||
# Set a higher stacktrace during development. Avoid configuring such | ||
# in production as building large stacktraces may be expensive. | ||
config :phoenix, :stacktrace_depth, 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use Mix.Config | ||
|
||
# For production, we configure the host to read the PORT | ||
# from the system environment. Therefore, you will need | ||
# to set PORT=80 before running your server. | ||
# | ||
# You should also configure the url host to something | ||
# meaningful, we use this information when generating URLs. | ||
# | ||
# Finally, we also include the path to a manifest | ||
# containing the digested version of static files. This | ||
# manifest is generated by the mix phoenix.digest task | ||
# which you typically run after static files are built. | ||
config :api_example, ApiExample.Endpoint, | ||
http: [port: {:system, "PORT"}], | ||
url: [host: "example.com", port: 80], | ||
cache_static_manifest: "priv/static/manifest.json" | ||
|
||
# Do not print debug messages in production | ||
config :logger, level: :info | ||
|
||
# ## SSL Support | ||
# | ||
# To get SSL working, you will need to add the `https` key | ||
# to the previous section and set your `:url` port to 443: | ||
# | ||
# config :api_example, ApiExample.Endpoint, | ||
# ... | ||
# url: [host: "example.com", port: 443], | ||
# https: [port: 443, | ||
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), | ||
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")] | ||
# | ||
# Where those two env variables return an absolute path to | ||
# the key and cert in disk or a relative path inside priv, | ||
# for example "priv/ssl/server.key". | ||
# | ||
# We also recommend setting `force_ssl`, ensuring no data is | ||
# ever sent via http, always redirecting to https: | ||
# | ||
# config :api_example, ApiExample.Endpoint, | ||
# force_ssl: [hsts: true] | ||
# | ||
# Check `Plug.SSL` for all available options in `force_ssl`. | ||
|
||
# ## Using releases | ||
# | ||
# If you are doing OTP releases, you need to instruct Phoenix | ||
# to start the server for all endpoints: | ||
# | ||
# config :phoenix, :serve_endpoints, true | ||
# | ||
# Alternatively, you can configure exactly which server to | ||
# start per endpoint: | ||
# | ||
# config :api_example, ApiExample.Endpoint, server: true | ||
# | ||
|
||
# Finally import the config/prod.secret.exs | ||
# which should be versioned separately. | ||
import_config "prod.secret.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use Mix.Config | ||
|
||
# We don't run a server during test. If one is required, | ||
# you can enable the server option below. | ||
config :api_example, ApiExample.Endpoint, | ||
http: [port: 4001], | ||
server: false | ||
|
||
# Print only warnings and errors during test | ||
config :logger, level: :warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule ApiExample do | ||
use Application | ||
|
||
# See http://elixir-lang.org/docs/stable/elixir/Application.html | ||
# for more information on OTP Applications | ||
def start(_type, _args) do | ||
import Supervisor.Spec | ||
|
||
# Define workers and child supervisors to be supervised | ||
children = [ | ||
# Start the endpoint when the application starts | ||
supervisor(ApiExample.Endpoint, []), | ||
# Start your own worker by calling: ApiExample.Worker.start_link(arg1, arg2, arg3) | ||
# worker(ApiExample.Worker, [arg1, arg2, arg3]), | ||
worker(ApiExample.Database, [%{users: []}, [name: Database]]), | ||
] | ||
|
||
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html | ||
# for other strategies and supported options | ||
opts = [strategy: :one_for_one, name: ApiExample.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
end | ||
|
||
# Tell Phoenix to update the endpoint configuration | ||
# whenever the application is updated. | ||
def config_change(changed, _new, removed) do | ||
ApiExample.Endpoint.config_change(changed, removed) | ||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule ApiExample.Database do | ||
use GenServer | ||
|
||
def start_link(state, opts \\ []) do | ||
GenServer.start_link(__MODULE__, state, opts) | ||
end | ||
|
||
def handle_cast({:add_user, user}, state) do | ||
case find_user(state.users, user["id"]) do | ||
:notfound -> {:noreply, %{state | users: [user] ++ state.users}} | ||
_ -> {:noreply, state} | ||
end | ||
end | ||
|
||
def handle_call({:find_user, id}, _from, state) do | ||
{:reply, find_user(state.users, id), state} | ||
end | ||
|
||
def handle_call({:delete_user, id}, _from, state) do | ||
case delete_user(state.users, [], id) do | ||
{:ok, users} -> {:reply, :ok, %{ state | users: users}} | ||
end | ||
end | ||
|
||
def handle_call({:find_user, id}, _from, state) do | ||
{:reply, find_user(state.users, id), state} | ||
end | ||
|
||
def handle_call(:get_users, _from, state) do | ||
{:reply, state.users, state} | ||
end | ||
|
||
def find_user([head | tail], id) do | ||
case head["id"] == id do | ||
true -> head | ||
false -> find_user(tail, id) | ||
end | ||
end | ||
|
||
def find_user([], id) do | ||
:notfound | ||
end | ||
|
||
def delete_user([head | tail], state, id) do | ||
case head["id"] == id do | ||
true -> delete_user(tail, state, id) | ||
false -> delete_user(tail, [head] ++ state, id) | ||
end | ||
end | ||
|
||
def delete_user([], state, id) do | ||
{:ok, state} | ||
end | ||
end |
Oops, something went wrong.