You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/12/25 17:45:13 UTC
[couchdb] 10/41: Speedup eunit: chttpd_db_bulk_get_test
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch speedup-test-suite
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 79622bfbb75510297a650f7faa61ef7e7e0045d4
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 19 13:20:22 2019 -0600
Speedup eunit: chttpd_db_bulk_get_test
Another example of moving mocks to a setup and using `meck:reset/1` in
the foreach fixture.
---
src/chttpd/test/eunit/chttpd_db_bulk_get_test.erl | 64 ++++++++++++-----------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/src/chttpd/test/eunit/chttpd_db_bulk_get_test.erl b/src/chttpd/test/eunit/chttpd_db_bulk_get_test.erl
index 864e707..1a34112 100644
--- a/src/chttpd/test/eunit/chttpd_db_bulk_get_test.erl
+++ b/src/chttpd/test/eunit/chttpd_db_bulk_get_test.erl
@@ -18,45 +18,51 @@
-define(TIMEOUT, 3000).
-setup() ->
+setup_all() ->
mock(config),
mock(chttpd),
mock(couch_epi),
mock(couch_httpd),
mock(couch_stats),
mock(fabric),
- mock(mochireq),
- Pid = spawn_accumulator(),
- Pid.
+ mock(mochireq).
+
+
+teardown_all(_) ->
+ meck:unload().
+
+
+setup() ->
+ spawn_accumulator().
teardown(Pid) ->
- ok = stop_accumulator(Pid),
- meck:unload(config),
- meck:unload(chttpd),
- meck:unload(couch_epi),
- meck:unload(couch_httpd),
- meck:unload(couch_stats),
- meck:unload(fabric),
- meck:unload(mochireq).
+ ok = stop_accumulator(Pid).
bulk_get_test_() ->
{
"/db/_bulk_get tests",
{
- foreach, fun setup/0, fun teardown/1,
- [
- fun should_require_docs_field/1,
- fun should_not_accept_specific_query_params/1,
- fun should_return_empty_results_on_no_docs/1,
- fun should_get_doc_with_all_revs/1,
- fun should_validate_doc_with_bad_id/1,
- fun should_validate_doc_with_bad_rev/1,
- fun should_validate_missing_doc/1,
- fun should_validate_bad_atts_since/1,
- fun should_include_attachments_when_atts_since_specified/1
- ]
+ setup,
+ fun setup_all/0,
+ fun teardown_all/1,
+ {
+ foreach,
+ fun setup/0,
+ fun teardown/1,
+ [
+ fun should_require_docs_field/1,
+ fun should_not_accept_specific_query_params/1,
+ fun should_return_empty_results_on_no_docs/1,
+ fun should_get_doc_with_all_revs/1,
+ fun should_validate_doc_with_bad_id/1,
+ fun should_validate_doc_with_bad_rev/1,
+ fun should_validate_missing_doc/1,
+ fun should_validate_bad_atts_since/1,
+ fun should_include_attachments_when_atts_since_specified/1
+ ]
+ }
}
}.
@@ -69,12 +75,10 @@ should_require_docs_field(_) ->
should_not_accept_specific_query_params(_) ->
Req = fake_request({[{<<"docs">>, []}]}),
lists:map(fun (Param) ->
- {Param, ?_assertThrow({bad_request, _},
- begin
- ok = meck:expect(chttpd, qs,
- fun(_) -> [{Param, ""}] end),
- chttpd_db:db_req(Req, nil)
- end)}
+ {Param, ?_assertThrow({bad_request, _}, begin
+ BadReq = Req#httpd{qs = [{Param, ""}]},
+ chttpd_db:db_req(BadReq, nil)
+ end)}
end, ["rev", "open_revs", "atts_since", "w", "new_edits"]).