Skip to content

Commit

Permalink
Fix [mix bench] task error and library updates
Browse files Browse the repository at this point in the history
  • Loading branch information
parroty committed Jan 22, 2017
1 parent 3df5e93 commit 9dd3d9d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Configurations for proxy is simplified.
- https://github.com/parroty/extwitter#proxy

* Fix [mix bench] task error and library updates.
- Update benchfella and remove some warning notes about setup/teardown.

0.7.3
------
#### Enhancements
Expand Down
17 changes: 0 additions & 17 deletions bench/README.md

This file was deleted.

53 changes: 21 additions & 32 deletions bench/stream_process_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@ defmodule ExTwitter.API.Streaming.Process.Bench do

@mock_tweet_json File.read!("fixture/mocks/tweet.json")

bench "process stream - single chunk", [req_id: make_ref, m: stub_tweet_parsing!] do
streamProcessor = spawn_stream_processor(self, req_id)
setup_all do
:meck.new(ExTwitter.API.Streaming, [:passthrough, :no_history])
{:ok, nil}
end

before_each_bench _ do
:meck.expect(
ExTwitter.API.Streaming, :parse_tweet_message,
fn(_,_) -> :parsed end
)
{:ok, nil}
end

after_each_bench _ do
:meck.unload(ExTwitter.API.Streaming)
end

bench "process stream - single chunk", [req_id: make_ref()] do
streamProcessor = spawn_stream_processor(self(), req_id)
send streamProcessor, {:http, {req_id, :stream, @mock_tweet_json}}
receive_processed_msgs()
end

bench "process stream - multi chunk", [req_id: make_ref, parts: msg_chunks, m: stub_tweet_parsing!] do
streamProcessor = spawn_stream_processor(self, req_id)
bench "process stream - multi chunk", [req_id: make_ref(), parts: msg_chunks()] do
streamProcessor = spawn_stream_processor(self(), req_id)
Enum.each(parts, fn part ->
send streamProcessor, {:http, {req_id, :stream, part}}
end)
Expand All @@ -36,34 +53,6 @@ defmodule ExTwitter.API.Streaming.Process.Bench do
end
end

# stub out tweet parsing so it doesnt affect benchmark time
# this is a fairly bad way to do it, but benchfella doesnt support a global
# "setup" phase just yet.
#
# also note that since benchfella doesn't support "after" callbacks to unload
# stubs, this stays loaded, so we all benchmarks in this file should be
# considered as using the stub.
defp stub_tweet_parsing! do
try do
:meck.validate(ExTwitter.API.Streaming)
rescue
ErlangError ->
Mix.Shell.IO.info """
WARNING! We just stubbed ExTwitter.API.Streaming.parse_tweet_message
This stub will be effect until this process ends.
If you are running multiple benchmarks, these ones should be run
independently of others, you can specify the files to run directly via
`mix bench bench/filename_bench.exs` etc.
"""
:meck.new(ExTwitter.API.Streaming, [:passthrough, :no_history])
:meck.expect(
ExTwitter.API.Streaming, :parse_tweet_message,
fn(_,_) -> :parsed end
)
end
end

# fake chunked messages to emulate chunked network traffic
defp msg_chunks, do: chunkify(@mock_tweet_json, 20)
defp chunkify(msg, n) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule ExTwitter.Mixfile do
{:ex_doc, ">= 0.0.0", only: [:dev, :docs]},
{:earmark, "~> 0.1", only: [:dev, :docs]},
{:inch_ex, "~> 0.5.1", only: :docs},
{:benchfella, github: "alco/benchfella", only: :dev}
{:benchfella, "~> 0.3.3", only: :dev}
]
end

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%{"benchfella": {:git, "https://github.com/alco/benchfella.git", "6a6abf836d4afbd2ab3b9a44fbc41afbba6a43e2", []},
%{"benchfella": {:hex, :benchfella, "0.3.3", "bbde48b5fe1ef556baa7ad933008e214e050e81ddb0916350715f5759fb35c0c", [:mix], []},
"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
"combine": {:hex, :combine, "0.7.0"},
"earmark": {:hex, :earmark, "0.1.19", "ffec54f520a11b711532c23d8a52b75a74c09697062d10613fa2dbdf8a9db36e", [:mix], []},
Expand Down

0 comments on commit 9dd3d9d

Please sign in to comment.