From 9dd3d9df9da1d0b0e9222e35a8d8b58f8791dd2d Mon Sep 17 00:00:00 2001 From: parroty Date: Sun, 22 Jan 2017 22:48:41 +0900 Subject: [PATCH] Fix [mix bench] task error and library updates --- CHANGELOG.md | 3 ++ bench/README.md | 17 ----------- bench/stream_process_bench.exs | 53 ++++++++++++++-------------------- mix.exs | 2 +- mix.lock | 2 +- 5 files changed, 26 insertions(+), 51 deletions(-) delete mode 100644 bench/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 42f5cd7..64de935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bench/README.md b/bench/README.md deleted file mode 100644 index e0d0571..0000000 --- a/bench/README.md +++ /dev/null @@ -1,17 +0,0 @@ -Note about these benchmarks: - -The `stream_process_bench.exs` script uses Meck to stub out the -`ExTwitter.API.Streaming.parse_tweet` function for benchmark isolation. - -However, benchfella does not currently support teardown phases to undo this -stub after the completion of the bench. - -Therefore, if you run them all via the default `mix bench` task (which loads and -runs all benchmarks in this directory), other benchmarks which depend on that -call will get unexpected results. - -For now, just run each benchmark script you want individually directly, e.g. - - mix bench bench/stream_parse_bench.exs - -Sorry for the inconvenience! diff --git a/bench/stream_process_bench.exs b/bench/stream_process_bench.exs index 0733664..accba14 100644 --- a/bench/stream_process_bench.exs +++ b/bench/stream_process_bench.exs @@ -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) @@ -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 diff --git a/mix.exs b/mix.exs index 5b51c3b..3b6e1b3 100644 --- a/mix.exs +++ b/mix.exs @@ -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 diff --git a/mix.lock b/mix.lock index b038114..dd8aeb0 100644 --- a/mix.lock +++ b/mix.lock @@ -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], []},