summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-09-29 23:31:40 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-09-29 23:31:40 +0000
commitf041f63d58315f536f77d63fb9a40b925f5b841b (patch)
treee1c01a04b33d250713c3dbc68b42ea08ec0cb865
parent1655280635e38f05f5e2bbd1f945b4d00c84c57b (diff)
downloadcouchdb-f041f63d58315f536f77d63fb9a40b925f5b841b.tar.gz
Remove usage of http module from etap tests
This module is deprecated in OTP R15, which is going to be released by the end of this year. The etap tests now use ibrowse instead. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1177459 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-xtest/etap/072-cleanup.t8
-rwxr-xr-xtest/etap/140-attachment-comp.t331
-rwxr-xr-xtest/etap/150-invalid-view-seq.t15
-rwxr-xr-xtest/etap/200-view-group-no-db-leaks.t33
-rwxr-xr-xtest/etap/220-compaction-daemon.t8
-rw-r--r--test/etap/test_util.erl.in30
6 files changed, 192 insertions, 233 deletions
diff --git a/test/etap/072-cleanup.t b/test/etap/072-cleanup.t
index 79cf37522..bd420f4d4 100755
--- a/test/etap/072-cleanup.t
+++ b/test/etap/072-cleanup.t
@@ -41,7 +41,6 @@ main(_) ->
test() ->
{ok, _} = couch_server_sup:start_link(test_util:config_files()),
- ok = application:start(inets),
couch_server:delete(?TEST_DB, []),
timer:sleep(1000),
@@ -110,11 +109,8 @@ db_url() ->
binary_to_list(?TEST_DB).
query_view(DDoc, View) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/_design/" ++ DDoc ++ "/_view/" ++ View, []},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/_design/" ++ DDoc ++ "/_view/" ++ View, [], get),
etap:is(Code, 200, "Built view index for " ++ DDoc ++ "."),
ok.
diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t
index 7b0e6f7d7..2b082c2a2 100755
--- a/test/etap/140-attachment-comp.t
+++ b/test/etap/140-attachment-comp.t
@@ -33,7 +33,6 @@ test() ->
couch_server_sup:start_link(test_util:config_files()),
put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
timer:sleep(1000),
couch_server:delete(test_db_name(), []),
couch_db:create(test_db_name(), []),
@@ -84,22 +83,20 @@ db_url() ->
binary_to_list(test_db_name()).
create_1st_text_att() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc1/readme.txt",
+ [{"Content-Type", "text/plain"}],
put,
- {db_url() ++ "/testdoc1/readme.txt", [],
- "text/plain", test_text_data()},
- [],
- [{sync, true}]),
+ test_text_data()),
etap:is(Code, 201, "Created text attachment using the standalone api"),
ok.
create_1st_png_att() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc2/icon.png",
+ [{"Content-Type", "image/png"}],
put,
- {db_url() ++ "/testdoc2/icon.png", [],
- "image/png", test_png_data()},
- [],
- [{sync, true}]),
+ test_png_data()),
etap:is(Code, 201, "Created png attachment using the standalone api"),
ok.
@@ -113,12 +110,11 @@ create_2nd_text_att() ->
]}
}]}}
]},
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc3",
+ [{"Content-Type", "application/json"}],
put,
- {db_url() ++ "/testdoc3", [],
- "application/json", ejson:encode(DocJson)},
- [],
- [{sync, true}]),
+ ejson:encode(DocJson)),
etap:is(Code, 201, "Created text attachment using the non-standalone api"),
ok.
@@ -132,22 +128,20 @@ create_2nd_png_att() ->
]}
}]}}
]},
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc4",
+ [{"Content-Type", "application/json"}],
put,
- {db_url() ++ "/testdoc4", [],
- "application/json", ejson:encode(DocJson)},
- [],
- [{sync, true}]),
+ ejson:encode(DocJson)),
etap:is(Code, 201, "Created png attachment using the non-standalone api"),
ok.
create_already_compressed_att(DocUri, AttName) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ DocUri ++ "/" ++ AttName,
+ [{"Content-Type", "text/plain"}, {"Content-Encoding", "gzip"}],
put,
- {DocUri ++ "/" ++ AttName, [{"Content-Encoding", "gzip"}],
- "text/plain", zlib:gzip(test_text_data())},
- [],
- [{sync, true}]),
+ zlib:gzip(test_text_data())),
etap:is(
Code,
201,
@@ -183,15 +177,14 @@ tests_for_2nd_png_att() ->
test_2nd_png_att_stub().
test_get_1st_text_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc1/readme.txt",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
+ Uncompressed = zlib:gunzip(iolist_to_binary(Body)),
etap:is(
Uncompressed,
test_text_data(),
@@ -200,46 +193,42 @@ test_get_1st_text_att_with_accept_encoding_gzip() ->
ok.
test_get_1st_text_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", []},
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc1/readme.txt",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
etap:is(
- Body,
+ iolist_to_binary(Body),
test_text_data(),
"received data for the 1st text attachment is ok"
),
ok.
test_get_1st_text_att_with_accept_encoding_deflate() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", [{"Accept-Encoding", "deflate"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc1/readme.txt",
+ [{"Accept-Encoding", "deflate"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
- Deflated = lists:member({"content-encoding", "deflate"}, Headers),
+ Deflated = lists:member({"Content-Encoding", "deflate"}, Headers),
etap:is(Deflated, false, "received body is not deflated"),
etap:is(
- Body,
+ iolist_to_binary(Body),
test_text_data(),
"received data for the 1st text attachment is ok"
),
ok.
test_get_1st_text_att_with_accept_encoding_deflate_only() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt",
- [{"Accept-Encoding", "deflate, *;q=0"}]},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc1/readme.txt",
+ [{"Accept-Encoding", "deflate, *;q=0"}],
+ get),
etap:is(
Code,
406,
@@ -248,60 +237,55 @@ test_get_1st_text_att_with_accept_encoding_deflate_only() ->
ok.
test_get_1st_png_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", []},
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2/icon.png",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
+ Encoding = couch_util:get_value("Content-Encoding", Headers),
etap:is(Encoding, undefined, "received body is not gziped"),
etap:is(
- Body,
+ iolist_to_binary(Body),
test_png_data(),
"received data for the 1st png attachment is ok"
),
ok.
test_get_1st_png_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2/icon.png",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
+ Encoding = couch_util:get_value("Content-Encoding", Headers),
etap:is(Encoding, undefined, "received body is not gziped"),
etap:is(
- Body,
+ iolist_to_binary(Body),
test_png_data(),
"received data for the 1st png attachment is ok"
),
ok.
test_get_1st_png_att_with_accept_encoding_deflate() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", [{"Accept-Encoding", "deflate"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2/icon.png",
+ [{"Accept-Encoding", "deflate"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
+ Encoding = couch_util:get_value("Content-Encoding", Headers),
etap:is(Encoding, undefined, "received body is in identity form"),
etap:is(
- Body,
+ iolist_to_binary(Body),
test_png_data(),
"received data for the 1st png attachment is ok"
),
ok.
test_get_doc_with_1st_text_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc1?attachments=true",
+ [{"Accept", "application/json"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
TextAttJson = couch_util:get_nested_json_value(
@@ -331,11 +315,10 @@ test_get_doc_with_1st_text_att() ->
ok.
test_1st_text_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1?att_encoding_info=true", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc1?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
{TextAttJson} = couch_util:get_nested_json_value(
@@ -345,7 +328,7 @@ test_1st_text_att_stub() ->
TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
etap:is(
TextAttLength,
- length(test_text_data()),
+ byte_size(test_text_data()),
"1st text attachment stub length matches the uncompressed length"
),
TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
@@ -363,12 +346,10 @@ test_1st_text_att_stub() ->
ok.
test_get_doc_with_1st_png_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2?attachments=true",
+ [{"Accept", "application/json"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
PngAttJson = couch_util:get_nested_json_value(
@@ -392,11 +373,10 @@ test_get_doc_with_1st_png_att() ->
ok.
test_1st_png_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2?att_encoding_info=true", []},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2?att_encoding_info=true",
+ [{"Accept", "application/json"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
{PngAttJson} = couch_util:get_nested_json_value(
@@ -406,7 +386,7 @@ test_1st_png_att_stub() ->
PngAttLength = couch_util:get_value(<<"length">>, PngAttJson),
etap:is(
PngAttLength,
- length(test_png_data()),
+ byte_size(test_png_data()),
"1st png attachment stub length matches the uncompressed length"
),
PngEncoding = couch_util:get_value(<<"encoding">>, PngAttJson),
@@ -424,15 +404,14 @@ test_1st_png_att_stub() ->
ok.
test_get_2nd_text_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc3/readme.txt",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
+ Uncompressed = zlib:gunzip(iolist_to_binary(Body)),
etap:is(
Uncompressed,
test_text_data(),
@@ -441,13 +420,12 @@ test_get_2nd_text_att_with_accept_encoding_gzip() ->
ok.
test_get_2nd_text_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3/readme.txt", []},
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc3/readme.txt",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
etap:is(
Body,
@@ -457,13 +435,12 @@ test_get_2nd_text_att_without_accept_encoding_header() ->
ok.
test_get_2nd_png_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4/icon.png", []},
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc4/icon.png",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
etap:is(
Body,
@@ -473,13 +450,12 @@ test_get_2nd_png_att_without_accept_encoding_header() ->
ok.
test_get_2nd_png_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4/icon.png", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc4/icon.png",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
etap:is(
Body,
@@ -489,12 +465,10 @@ test_get_2nd_png_att_with_accept_encoding_gzip() ->
ok.
test_get_doc_with_2nd_text_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc3?attachments=true",
+ [{"Accept", "application/json"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
TextAttJson = couch_util:get_nested_json_value(
@@ -520,11 +494,10 @@ test_get_doc_with_2nd_text_att() ->
ok.
test_2nd_text_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3?att_encoding_info=true", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc3?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
{TextAttJson} = couch_util:get_nested_json_value(
@@ -534,7 +507,7 @@ test_2nd_text_att_stub() ->
TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
etap:is(
TextAttLength,
- length(test_text_data()),
+ byte_size(test_text_data()),
"2nd text attachment stub length matches the uncompressed length"
),
TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
@@ -552,12 +525,10 @@ test_2nd_text_att_stub() ->
ok.
test_get_doc_with_2nd_png_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc4?attachments=true",
+ [{"Accept", "application/json"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
PngAttJson = couch_util:get_nested_json_value(
@@ -581,11 +552,10 @@ test_get_doc_with_2nd_png_att() ->
ok.
test_2nd_png_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4?att_encoding_info=true", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc4?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
{PngAttJson} = couch_util:get_nested_json_value(
@@ -595,7 +565,7 @@ test_2nd_png_att_stub() ->
PngAttLength = couch_util:get_value(<<"length">>, PngAttJson),
etap:is(
PngAttLength,
- length(test_png_data()),
+ byte_size(test_png_data()),
"2nd png attachment stub length matches the uncompressed length"
),
PngEncoding = couch_util:get_value(<<"encoding">>, PngAttJson),
@@ -618,43 +588,40 @@ test_already_compressed_att(DocUri, AttName) ->
test_get_already_compressed_att_stub(DocUri, AttName).
test_get_already_compressed_att_with_accept_gzip(DocUri, AttName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {DocUri ++ "/" ++ AttName, [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ DocUri ++ "/" ++ AttName,
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, true, "received body is gziped"),
etap:is(
- iolist_to_binary(Body),
- iolist_to_binary(zlib:gzip(test_text_data())),
+ Body,
+ zlib:gzip(test_text_data()),
"received data for the already compressed attachment is ok"
),
ok.
test_get_already_compressed_att_without_accept(DocUri, AttName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {DocUri ++ "/" ++ AttName, []},
+ {ok, Code, Headers, Body} = test_util:request(
+ DocUri ++ "/" ++ AttName,
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, false, "received body is not gziped"),
etap:is(
- iolist_to_binary(Body),
- iolist_to_binary(test_text_data()),
+ Body,
+ test_text_data(),
"received data for the already compressed attachment is ok"
),
ok.
test_get_already_compressed_att_stub(DocUri, AttName) ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {DocUri ++ "?att_encoding_info=true", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ DocUri ++ "?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = ejson:decode(Body),
{AttJson} = couch_util:get_nested_json_value(
@@ -685,12 +652,11 @@ test_get_already_compressed_att_stub(DocUri, AttName) ->
test_create_already_compressed_att_with_invalid_content_encoding(
DocUri, AttName, AttData, Encoding) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ DocUri ++ "/" ++ AttName,
+ [{"Content-Encoding", Encoding}, {"Content-Type", "text/plain"}],
put,
- {DocUri ++ "/" ++ AttName, [{"Content-Encoding", Encoding}],
- "text/plain", AttData},
- [],
- [{sync, true}]),
+ AttData),
etap:is(
Code,
415,
@@ -700,29 +666,26 @@ test_create_already_compressed_att_with_invalid_content_encoding(
ok.
test_compressible_type_with_parameters() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/testdoc5/readme.txt",
+ [{"Content-Type", "text/plain; charset=UTF-8"}],
put,
- {db_url() ++ "/testdoc5/readme.txt", [],
- "text/plain; charset=UTF-8", test_text_data()},
- [],
- [{sync, true}]),
+ test_text_data()),
etap:is(Code, 201, "Created text attachment with MIME type "
"'text/plain; charset=UTF-8' using the standalone api"),
- {ok, {{_, Code2, _}, Headers2, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc5/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code2, Headers2, Body} = test_util:request(
+ db_url() ++ "/testdoc5/readme.txt",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code2, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers2),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers2),
etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
+ Uncompressed = zlib:gunzip(iolist_to_binary(Body)),
etap:is(Uncompressed, test_text_data(), "received data is gzipped"),
- {ok, {{_, Code3, _}, _Headers3, Body3}} = http:request(
- get,
- {db_url() ++ "/testdoc5?att_encoding_info=true", []},
+ {ok, Code3, _Headers3, Body3} = test_util:request(
+ db_url() ++ "/testdoc5?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code3, 200, "HTTP response code is 200"),
Json = ejson:decode(Body3),
{TextAttJson} = couch_util:get_nested_json_value(
@@ -732,7 +695,7 @@ test_compressible_type_with_parameters() ->
TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
etap:is(
TextAttLength,
- length(test_text_data()),
+ byte_size(test_text_data()),
"text attachment stub length matches the uncompressed length"
),
TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
@@ -753,10 +716,10 @@ test_png_data() ->
{ok, Data} = file:read_file(
test_util:source_file("share/www/image/logo.png")
),
- binary_to_list(Data).
+ Data.
test_text_data() ->
{ok, Data} = file:read_file(
test_util:source_file("README")
),
- binary_to_list(Data).
+ Data.
diff --git a/test/etap/150-invalid-view-seq.t b/test/etap/150-invalid-view-seq.t
index 6270c2f67..681875aff 100755
--- a/test/etap/150-invalid-view-seq.t
+++ b/test/etap/150-invalid-view-seq.t
@@ -52,7 +52,6 @@ test() ->
put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
create_new_doc(),
query_view_before_restore_backup(),
@@ -133,11 +132,8 @@ db_url() ->
binary_to_list(test_db_name()).
query_view_before_restore_backup() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/bar", []},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/_design/foo/_view/bar", [], get),
etap:is(Code, 200, "Got view response before restoring backup."),
ViewJson = ejson:decode(Body),
Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
@@ -171,11 +167,8 @@ restore_backup_db_file() ->
ok.
query_view_after_restore_backup() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/bar", []},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/_design/foo/_view/bar", [], get),
etap:is(Code, 200, "Got view response after restoring backup."),
ViewJson = ejson:decode(Body),
Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
diff --git a/test/etap/200-view-group-no-db-leaks.t b/test/etap/200-view-group-no-db-leaks.t
index 20be0d4c3..7ad743946 100755
--- a/test/etap/200-view-group-no-db-leaks.t
+++ b/test/etap/200-view-group-no-db-leaks.t
@@ -19,21 +19,6 @@
handler
}).
--define(LATEST_DISK_VERSION, 6).
-
--record(db_header,
- {disk_version = ?LATEST_DISK_VERSION,
- update_seq = 0,
- unused = 0,
- fulldocinfo_by_id_btree_state = nil,
- docinfo_by_seq_btree_state = nil,
- local_docs_btree_state = nil,
- purge_seq = 0,
- purged_docs = nil,
- security_ptr = nil,
- revs_limit = 1000
-}).
-
-record(db, {
main_pid = nil,
update_pid = nil,
@@ -42,7 +27,7 @@
fd,
updater_fd,
fd_ref_counter,
- header = #db_header{},
+ header = nil,
committed_update_seq,
fulldocinfo_by_id_btree,
docinfo_by_seq_btree,
@@ -82,7 +67,6 @@ test() ->
timer:sleep(1000),
put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
delete_db(),
create_db(),
@@ -177,11 +161,10 @@ compact_view_group() ->
wait_view_compact_done(0) ->
etap:bail("View group compaction failed to finish.");
wait_view_compact_done(N) ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++ "/_info", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++ "/_info",
[],
- [{sync, true}]),
+ get),
case Code of
200 -> ok;
_ -> etap:bail("Invalid view group info.")
@@ -258,11 +241,9 @@ db_url() ->
binary_to_list(test_db_name()).
query_view() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++
- "/_view/bar", []},
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++ "/_view/bar",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "got view response"),
ok.
diff --git a/test/etap/220-compaction-daemon.t b/test/etap/220-compaction-daemon.t
index db606c0c1..4c63b66b4 100755
--- a/test/etap/220-compaction-daemon.t
+++ b/test/etap/220-compaction-daemon.t
@@ -40,7 +40,6 @@ test() ->
timer:sleep(1000),
put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
disable_compact_daemon(),
@@ -175,11 +174,8 @@ db_url() ->
binary_to_list(test_db_name()).
query_view() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/foo", []},
- [],
- [{sync, true}]),
+ {ok, Code, _Headers, _Body} = test_util:request(
+ db_url() ++ "/_design/foo/_view/foo", [], get),
case Code of
200 ->
ok;
diff --git a/test/etap/test_util.erl.in b/test/etap/test_util.erl.in
index aba8cc7eb..92b9208fd 100644
--- a/test/etap/test_util.erl.in
+++ b/test/etap/test_util.erl.in
@@ -15,6 +15,7 @@
-export([init_code_path/0]).
-export([source_file/1, build_file/1, config_files/0]).
-export([run/2]).
+-export([request/3, request/4]).
srcdir() ->
"@abs_top_srcdir@".
@@ -62,3 +63,32 @@ run(Plan, Fun) ->
etap:bail(Other)
end,
ok.
+
+
+request(Url, Headers, Method) ->
+ request(Url, Headers, Method, []).
+
+request(Url, Headers, Method, Body) ->
+ request(Url, Headers, Method, Body, 3).
+
+request(_Url, _Headers, _Method, _Body, 0) ->
+ {error, request_failed};
+request(Url, Headers, Method, Body, N) ->
+ case code:is_loaded(ibrowse) of
+ false ->
+ {ok, _} = ibrowse:start();
+ _ ->
+ ok
+ end,
+ case ibrowse:send_req(Url, Headers, Method, Body) of
+ {ok, Code0, RespHeaders, RespBody0} ->
+ Code = list_to_integer(Code0),
+ RespBody = iolist_to_binary(RespBody0),
+ {ok, Code, RespHeaders, RespBody};
+ {error, {'EXIT', {normal, _}}} ->
+ % Connection closed right after a successful request that
+ % used the same connection.
+ request(Url, Headers, Method, Body, N - 1);
+ Error ->
+ Error
+ end.