diff options
author | Nick Vatamaniuc <vatamane@gmail.com> | 2022-08-18 21:25:37 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2022-08-19 13:18:59 -0400 |
commit | 9a6875f6b2e1b83bd4128f72fc4c4d01d14dfc7c (patch) | |
tree | a7c93e21b9848ff3600b1e68dae31aec5f5e17a3 | |
parent | 065b212e5929d088abb9f38787c9bfeefc0c0b19 (diff) | |
download | couchdb-9a6875f6b2e1b83bd4128f72fc4c4d01d14dfc7c.tar.gz |
Update couch_replicator_large_atts_tests
Use commong setup functions and TDEF_FE macro.
Removing the foreachx and the remote vs local junk really trimmed down the
size. The test content was tiny compared to the clunky EUnit setup logic.
-rw-r--r-- | src/couch_replicator/test/eunit/couch_replicator_large_atts_tests.erl | 92 |
1 files changed, 23 insertions, 69 deletions
diff --git a/src/couch_replicator/test/eunit/couch_replicator_large_atts_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_large_atts_tests.erl index 2f0e2a1f0..8190c7205 100644 --- a/src/couch_replicator/test/eunit/couch_replicator_large_atts_tests.erl +++ b/src/couch_replicator/test/eunit/couch_replicator_large_atts_tests.erl @@ -14,12 +14,7 @@ -include_lib("couch/include/couch_eunit.hrl"). -include_lib("couch/include/couch_db.hrl"). - --import(couch_replicator_test_helper, [ - db_url/1, - replicate/2, - compare_dbs/2 -]). +-include("couch_replicator_test.hrl"). -define(ATT_SIZE_1, 2 * 1024 * 1024). -define(ATT_SIZE_2, round(6.6 * 1024 * 1024)). @@ -27,83 +22,37 @@ -define(TIMEOUT_EUNIT, 120). setup() -> - DbName = ?tempdb(), - {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]), - ok = couch_db:close(Db), - DbName. - -setup(remote) -> - {remote, setup()}; -setup({A, B}) -> - Ctx = test_util:start_couch([couch_replicator]), - config:set("attachments", "compressible_types", "text/*", false), - Source = setup(A), - Target = setup(B), - {Ctx, {Source, Target}}. - -teardown({remote, DbName}) -> - teardown(DbName); -teardown(DbName) -> - ok = couch_server:delete(DbName, [?ADMIN_CTX]), - ok. + Ctx = couch_replicator_test_helper:test_setup(), + config:set("attachments", "compressible_types", "text/*", _Persist = false), + Ctx. -teardown(_, {Ctx, {Source, Target}}) -> - teardown(Source), - teardown(Target), - - ok = application:stop(couch_replicator), - ok = test_util:stop_couch(Ctx). +teardown(Ctx) -> + config:delete("attachments", "compressible_types", _Persist = false), + couch_replicator_test_helper:test_teardown(Ctx). large_atts_test_() -> - Pairs = [{remote, remote}], { "Replicate docs with large attachments", { - foreachx, - fun setup/1, - fun teardown/2, + foreach, + fun setup/0, + fun teardown/1, [ - {Pair, fun should_populate_replicate_compact/2} - || Pair <- Pairs + ?TDEF_FE(should_replicate_atts, ?TIMEOUT_EUNIT) ] } }. -should_populate_replicate_compact({From, To}, {_Ctx, {Source, Target}}) -> - { - lists:flatten(io_lib:format("~p -> ~p", [From, To])), - {inorder, [ - should_populate_source(Source), - should_replicate(Source, Target), - should_compare_databases(Source, Target) - ]} - }. - -should_populate_source({remote, Source}) -> - should_populate_source(Source); -should_populate_source(Source) -> - {timeout, ?TIMEOUT_EUNIT, ?_test(populate_db(Source, ?DOCS_COUNT))}. - -should_replicate({remote, Source}, Target) -> - should_replicate(db_url(Source), Target); -should_replicate(Source, {remote, Target}) -> - should_replicate(Source, db_url(Target)); -should_replicate(Source, Target) -> - {timeout, ?TIMEOUT_EUNIT, ?_test(replicate(Source, Target))}. - -should_compare_databases({remote, Source}, Target) -> - should_compare_databases(Source, Target); -should_compare_databases(Source, {remote, Target}) -> - should_compare_databases(Source, Target); -should_compare_databases(Source, Target) -> - {timeout, ?TIMEOUT_EUNIT, ?_test(compare_dbs(Source, Target))}. +should_replicate_atts({_Ctx, {Source, Target}}) -> + populate_db(Source, ?DOCS_COUNT), + ?assertEqual(ok, replicate(Source, Target)), + couch_replicator_test_helper:cluster_compare_dbs(Source, Target). populate_db(DbName, DocCount) -> - {ok, Db} = couch_db:open_int(DbName, []), Docs = lists:foldl( fun(DocIdCounter, Acc) -> Doc = #doc{ - id = iolist_to_binary(["doc", integer_to_list(DocIdCounter)]), + id = integer_to_binary(DocIdCounter), body = {[]}, atts = [ att(<<"att1">>, ?ATT_SIZE_1, <<"text/plain">>), @@ -115,8 +64,7 @@ populate_db(DbName, DocCount) -> [], lists:seq(1, DocCount) ), - {ok, _} = couch_db:update_docs(Db, Docs, []), - couch_db:close(Db). + {ok, _} = fabric:update_docs(DbName, Docs, [?ADMIN_CTX]). att(Name, Size, Type) -> couch_att:new([ @@ -125,3 +73,9 @@ att(Name, Size, Type) -> {att_len, Size}, {data, fun(Count) -> crypto:strong_rand_bytes(Count) end} ]). + +db_url(DbName) -> + couch_replicator_test_helper:cluster_db_url(DbName). + +replicate(Source, Target) -> + couch_replicator_test_helper:replicate(db_url(Source), db_url(Target)). |