summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-01-18 10:52:24 -0600
committerJan Lehnardt <jan@apache.org>2019-02-17 18:33:19 +0100
commitb50c6fc1caf3f2a55df07a8c39ab39093430a48f (patch)
treeff4656cd3ddd6a250c5628701512a465f160220b
parent4ea767234c29cd07e8afed8206dc725f0005fff7 (diff)
downloadcouchdb-b50c6fc1caf3f2a55df07a8c39ab39093430a48f.tar.gz
Fix timeout in chttpd_purge_tests
-rw-r--r--src/chttpd/test/chttpd_purge_tests.erl36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/chttpd/test/chttpd_purge_tests.erl b/src/chttpd/test/chttpd_purge_tests.erl
index 50f7e18e5..dbd73de1f 100644
--- a/src/chttpd/test/chttpd_purge_tests.erl
+++ b/src/chttpd/test/chttpd_purge_tests.erl
@@ -52,6 +52,11 @@ create_doc(Url, Id, Content) ->
[?CONTENT_JSON, ?AUTH], "{\"mr\": \"" ++ Content ++ "\"}").
+create_docs(Url, Docs) ->
+ test_request:post(Url ++ "/_bulk_docs",
+ [?CONTENT_JSON, ?AUTH], ?JSON_ENCODE({[{docs, Docs}]})).
+
+
delete_db(Url) ->
{ok, 200, _, _} = test_request:delete(Url, [?AUTH]).
@@ -141,20 +146,29 @@ test_ok_purge_request(Url) ->
test_ok_purge_request_with_101_docid(Url) ->
?_test(begin
PurgedDocsNum = 101,
- IdsRevsEJson = lists:foldl(fun(I, CIdRevs) ->
+ Docs = lists:foldl(fun(I, Acc) ->
Id = list_to_binary(integer_to_list(I)),
- {ok, _, _, Body} = create_doc(Url, Id),
- {Json} = ?JSON_DECODE(Body),
- Rev = couch_util:get_value(<<"rev">>, Json, undefined),
- [{Id, [Rev]} | CIdRevs]
- end, [], lists:seq(1, PurgedDocsNum)),
+ Doc = {[{<<"_id">>, Id}, {value, I}]},
+ [Doc | Acc]
+ end, [], lists:seq(1, PurgedDocsNum)),
+
+ {ok, _, _, Body} = create_docs(Url, Docs),
+ BodyJson = ?JSON_DECODE(Body),
+
+ PurgeBody = lists:map(fun({DocResp}) ->
+ Id = couch_util:get_value(<<"id">>, DocResp, undefined),
+ Rev = couch_util:get_value(<<"rev">>, DocResp, undefined),
+ {Id, [Rev]}
+ end, BodyJson),
- IdsRevs = binary_to_list(?JSON_ENCODE({IdsRevsEJson})),
ok = config:set("purge", "max_document_id_number", "101"),
- {ok, Status, _, _} = test_request:post(Url ++ "/_purge/",
- [?CONTENT_JSON, ?AUTH], IdsRevs),
- ok = config:delete("purge", "max_document_id_number"),
- ?assert(Status =:= 201 orelse Status =:= 202)
+ try
+ {ok, Status, _, _} = test_request:post(Url ++ "/_purge/",
+ [?CONTENT_JSON, ?AUTH], ?JSON_ENCODE({PurgeBody})),
+ ?assert(Status =:= 201 orelse Status =:= 202)
+ after
+ ok = config:delete("purge", "max_document_id_number")
+ end
end).