Skip to content

Commit

Permalink
Code for step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos committed May 2, 2020
1 parent 9efadef commit 1ec59d2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions load_test.exs
@@ -0,0 +1,33 @@
base_url = "http://localhost:4000/api/used_cars"
wait_time_per_query_ms = 100
total_requests = 100

:ok = :inets.start()

Enum.each(1..total_requests, fn count ->
random_num = :rand.uniform(10)

url =
cond do
random_num <= 5 ->
"#{base_url}?make=ferrari"

random_num <= 7 ->
"#{base_url}?model=F8"

random_num == 8 ->
"#{base_url}?min_year=1990"

random_num == 9 ->
"#{base_url}?max_price=200000"

true ->
"#{base_url}?max_mileage=50000"
end

:httpc.request(:get, {String.to_charlist(url), []}, [], [])

if rem(count, 10) == 0, do: IO.puts("Completed #{count} requests")

:timer.sleep(wait_time_per_query_ms)
end)

0 comments on commit 1ec59d2

Please sign in to comment.