diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-12-25 11:41:23 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-12-25 13:52:32 -0600 |
commit | 8fba5240c898f19fdef26f5fa74c5383f9d59b7e (patch) | |
tree | 90a0497ff8bf0c569671f9ebb39231a035e39ab3 | |
parent | b217fb49ac8908a66d9e9e5040a4c5d63e47c347 (diff) | |
download | couchdb-8fba5240c898f19fdef26f5fa74c5383f9d59b7e.tar.gz |
Speedup eunit: fabric_doc_update
-rw-r--r-- | src/fabric/src/fabric_doc_update.erl | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/fabric/src/fabric_doc_update.erl b/src/fabric/src/fabric_doc_update.erl index c108c9a32..69babc14b 100644 --- a/src/fabric/src/fabric_doc_update.erl +++ b/src/fabric/src/fabric_doc_update.erl @@ -219,13 +219,36 @@ validate_atomic_update(_DbName, AllDocs, true) -> end, AllDocs), throw({aborted, PreCommitFailures}). -% eunits -doc_update1_test() -> - meck:new(couch_stats), - meck:expect(couch_stats, increment_counter, fun(_) -> ok end), - meck:new(couch_log), + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + + +setup_all() -> + meck:new([couch_log, couch_stats]), meck:expect(couch_log, warning, fun(_,_) -> ok end), + meck:expect(couch_stats, increment_counter, fun(_) -> ok end). + + +teardown_all(_) -> + meck:unload(). + +doc_update_test_() -> + { + setup, + fun setup_all/0, + fun teardown_all/1, + [ + fun doc_update1/0, + fun doc_update2/0, + fun doc_update3/0 + ] + }. + + +% eunits +doc_update1() -> Doc1 = #doc{revs = {1,[<<"foo">>]}}, Doc2 = #doc{revs = {1,[<<"bar">>]}}, Docs = [Doc1], @@ -294,17 +317,9 @@ doc_update1_test() -> ?assertEqual( {error, [{Doc1,{accepted,"A"}},{Doc2,{error,internal_server_error}}]}, ReplyW5 - ), - meck:unload(couch_log), - meck:unload(couch_stats). - - -doc_update2_test() -> - meck:new(couch_stats), - meck:expect(couch_stats, increment_counter, fun(_) -> ok end), - meck:new(couch_log), - meck:expect(couch_log, warning, fun(_,_) -> ok end), + ). +doc_update2() -> Doc1 = #doc{revs = {1,[<<"foo">>]}}, Doc2 = #doc{revs = {1,[<<"bar">>]}}, Docs = [Doc2, Doc1], @@ -326,11 +341,9 @@ doc_update2_test() -> handle_message({rexi_EXIT, 1},lists:nth(3,Shards),Acc2), ?assertEqual({accepted, [{Doc1,{accepted,Doc2}}, {Doc2,{accepted,Doc1}}]}, - Reply), - meck:unload(couch_log), - meck:unload(couch_stats). + Reply). -doc_update3_test() -> +doc_update3() -> Doc1 = #doc{revs = {1,[<<"foo">>]}}, Doc2 = #doc{revs = {1,[<<"bar">>]}}, Docs = [Doc2, Doc1], @@ -360,3 +373,5 @@ group_docs_by_shard_hack(_DbName, Shards, Docs) -> dict:append(Shard, Doc, D1) end, D0, Shards) end, dict:new(), Docs)). + +-endif. |