summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-09-29 23:34:40 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-09-29 23:34:40 +0000
commit1285cd95c8fe351991218f886bbfe28d9a9a3b09 (patch)
treea62af53acc1fb9be4e943ab1935e6fa92889863f /test
parent89a5c28775f24f2706f443c76afa3edf9df78ce4 (diff)
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. This is a backport of revision 1177459 from trunk. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1177463 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rwxr-xr-xtest/etap/072-cleanup.t8
-rwxr-xr-xtest/etap/113-replication-attachment-comp.t77
-rwxr-xr-xtest/etap/140-attachment-comp.t319
-rwxr-xr-xtest/etap/150-invalid-view-seq.t15
-rwxr-xr-xtest/etap/200-view-group-no-db-leaks.t33
-rw-r--r--test/etap/test_util.erl.in28
6 files changed, 217 insertions, 263 deletions
diff --git a/test/etap/072-cleanup.t b/test/etap/072-cleanup.t
index 61790bc6..6f97193d 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/113-replication-attachment-comp.t b/test/etap/113-replication-attachment-comp.t
index e30a96bc..bc98ca18 100755
--- a/test/etap/113-replication-attachment-comp.t
+++ b/test/etap/113-replication-attachment-comp.t
@@ -41,8 +41,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),
- ibrowse:start(),
timer:sleep(1000),
%
@@ -133,12 +131,11 @@ test() ->
ok.
put_text_att(DbName) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url(DbName) ++ "/testdoc1/readme.txt",
+ [{"Content-Type", "text/plain"}],
put,
- {db_url(DbName) ++ "/testdoc1/readme.txt", [],
- "text/plain", test_text_data()},
- [],
- [{sync, true}]),
+ test_text_data()),
etap:is(Code, 201, "Created text attachment"),
ok.
@@ -147,12 +144,11 @@ do_pull_replication(SourceDbName, TargetDbName) ->
{<<"source">>, list_to_binary(db_url(SourceDbName))},
{<<"target">>, TargetDbName}
]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
+ {ok, Code, _Headers, Body} = test_util:request(
+ rep_url(),
+ [{"Content-Type", "application/json"}],
post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
+ iolist_to_binary(couch_util:json_encode(RepObj))),
etap:is(Code, 200, "Pull replication successfully triggered"),
Json = couch_util:json_decode(Body),
RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
@@ -164,12 +160,11 @@ do_push_replication(SourceDbName, TargetDbName) ->
{<<"source">>, SourceDbName},
{<<"target">>, list_to_binary(db_url(TargetDbName))}
]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
+ {ok, Code, _Headers, Body} = test_util:request(
+ rep_url(),
+ [{"Content-Type", "application/json"}],
post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
+ iolist_to_binary(couch_util:json_encode(RepObj))),
etap:is(Code, 200, "Push replication successfully triggered"),
Json = couch_util:json_decode(Body),
RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
@@ -181,12 +176,11 @@ do_local_replication(SourceDbName, TargetDbName) ->
{<<"source">>, SourceDbName},
{<<"target">>, TargetDbName}
]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
+ {ok, Code, _Headers, Body} = test_util:request(
+ rep_url(),
+ [{"Content-Type", "application/json"}],
post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
+ iolist_to_binary(couch_util:json_encode(RepObj))),
etap:is(Code, 200, "Local replication successfully triggered"),
Json = couch_util:json_decode(Body),
RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
@@ -194,16 +188,14 @@ do_local_replication(SourceDbName, TargetDbName) ->
ok.
check_att_is_compressed(DbName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url(DbName) ++ "/testdoc1/readme.txt",
- [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url(DbName) ++ "/testdoc1/readme.txt",
+ [{"Accept-Encoding", "gzip"}],
+ get),
etap:is(Code, 200, "HTTP response code for the attachment request is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(Gziped, true, "The attachment was received in compressed form"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
+ Uncompressed = zlib:gunzip(Body),
etap:is(
Uncompressed,
test_text_data(),
@@ -212,13 +204,12 @@ check_att_is_compressed(DbName) ->
ok.
check_server_can_decompress_att(DbName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url(DbName) ++ "/testdoc1/readme.txt", []},
+ {ok, Code, Headers, Body} = test_util:request(
+ db_url(DbName) ++ "/testdoc1/readme.txt",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code for the attachment request is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
+ Gziped = lists:member({"Content-Encoding", "gzip"}, Headers),
etap:is(
Gziped, false, "The attachment was not received in compressed form"
),
@@ -230,11 +221,10 @@ check_server_can_decompress_att(DbName) ->
ok.
check_att_stubs(SourceDbName, TargetDbName) ->
- {ok, {{_, Code1, _}, _Headers1, Body1}} = http:request(
- get,
- {db_url(SourceDbName) ++ "/testdoc1?att_encoding_info=true", []},
+ {ok, Code1, _Headers1, Body1} = test_util:request(
+ db_url(SourceDbName) ++ "/testdoc1?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(
Code1,
200,
@@ -245,11 +235,10 @@ check_att_stubs(SourceDbName, TargetDbName) ->
Json1,
[<<"_attachments">>, <<"readme.txt">>]
),
- {ok, {{_, Code2, _}, _Headers2, Body2}} = http:request(
- get,
- {db_url(TargetDbName) ++ "/testdoc1?att_encoding_info=true", []},
+ {ok, Code2, _Headers2, Body2} = test_util:request(
+ db_url(SourceDbName) ++ "/testdoc1?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(
Code2,
200,
@@ -311,4 +300,4 @@ rep_url() ->
test_text_data() ->
{ok, Data} = file:read_file(test_util:source_file("README")),
- binary_to_list(Data).
+ Data.
diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t
index 475f4fb0..861096a0 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", list_to_binary(couch_util:json_encode(DocJson))},
- [],
- [{sync, true}]),
+ iolist_to_binary(couch_util:json_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", list_to_binary(couch_util:json_encode(DocJson))},
- [],
- [{sync, true}]),
+ iolist_to_binary(couch_util:json_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(Body),
etap:is(
Uncompressed,
test_text_data(),
@@ -200,13 +193,12 @@ 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,
@@ -216,15 +208,14 @@ test_get_1st_text_att_without_accept_encoding_header() ->
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,
@@ -234,12 +225,10 @@ test_get_1st_text_att_with_accept_encoding_deflate() ->
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,13 +237,12 @@ 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,
@@ -264,13 +252,12 @@ test_get_1st_png_att_without_accept_encoding_header() ->
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,
@@ -280,13 +267,12 @@ test_get_1st_png_att_with_accept_encoding_gzip() ->
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,
@@ -296,12 +282,10 @@ test_get_1st_png_att_with_accept_encoding_deflate() ->
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 = couch_util:json_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 = couch_util:json_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 = couch_util:json_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", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/testdoc2?att_encoding_info=true",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "HTTP response code is 200"),
Json = couch_util:json_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(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 = couch_util:json_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 = couch_util:json_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 = couch_util:json_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 = couch_util:json_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 = couch_util:json_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(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 = couch_util:json_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 594d3416..bc44592e 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,10 @@ 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", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/_design/foo/_view/bar",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "Got view response before restoring backup."),
ViewJson = couch_util:json_decode(Body),
Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
@@ -171,11 +169,10 @@ restore_backup_db_file() ->
ok.
query_view_after_restore_backup() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/bar", []},
+ {ok, Code, _Headers, Body} = test_util:request(
+ db_url() ++ "/_design/foo/_view/bar",
[],
- [{sync, true}]),
+ get),
etap:is(Code, 200, "Got view response after restoring backup."),
ViewJson = couch_util:json_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 f506b7dc..6c076674 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, 5).
-
--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,
@@ -41,7 +26,7 @@
instance_start_time, % number of microsecs since jan 1 1970 as a binary string
fd,
fd_ref_counter,
- header = #db_header{},
+ header = nil,
committed_update_seq,
fulldocinfo_by_id_btree,
docinfo_by_seq_btree,
@@ -80,7 +65,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(),
@@ -171,11 +155,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.")
@@ -252,11 +235,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/test_util.erl.in b/test/etap/test_util.erl.in
index 460b0293..b986ff35 100644
--- a/test/etap/test_util.erl.in
+++ b/test/etap/test_util.erl.in
@@ -14,6 +14,7 @@
-export([init_code_path/0]).
-export([source_file/1, build_file/1, config_files/0]).
+-export([request/3, request/4]).
srcdir() ->
"@abs_top_srcdir@".
@@ -40,3 +41,30 @@ config_files() ->
source_file("test/etap/random_port.ini")
].
+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.