From 1285cd95c8fe351991218f886bbfe28d9a9a3b09 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Thu, 29 Sep 2011 23:34:40 +0000 Subject: 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 --- test/etap/072-cleanup.t | 8 +- test/etap/113-replication-attachment-comp.t | 77 +++---- test/etap/140-attachment-comp.t | 319 ++++++++++++---------------- test/etap/150-invalid-view-seq.t | 15 +- test/etap/200-view-group-no-db-leaks.t | 33 +-- test/etap/test_util.erl.in | 28 +++ 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. -- cgit v1.2.3 From e14981fff72c58d4b552aae51c877a9c01c997ef Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Fri, 30 Sep 2011 08:10:31 +0000 Subject: Replicator: skip documents with empty ID Due to a bug, older releases allowed the creation of documents with an empty ID, which are impossible to GET therefore making the replicator crash. This change simply skips such documents and logs an error message to inform users. This is a backport of revision 1177548 from trunk. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1177550 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_rep_changes_feed.erl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/couchdb/couch_rep_changes_feed.erl b/src/couchdb/couch_rep_changes_feed.erl index a0696bf2..636d5a0d 100644 --- a/src/couchdb/couch_rep_changes_feed.erl +++ b/src/couchdb/couch_rep_changes_feed.erl @@ -491,13 +491,30 @@ purge_req_messages(ReqId) -> ok end. -queue_changes_row(Row, #state{doc_ids = nil, count = Count, rows = Rows}) -> - {queue:in(Row, Rows), Count + 1}; +queue_changes_row(Row, #state{doc_ids = nil} = State) -> + maybe_queue_row(Row, State); queue_changes_row({RowProps} = Row, - #state{doc_ids = Ids, count = Count, rows = Rows}) -> + #state{doc_ids = Ids, count = Count, rows = Rows} = State) -> case lists:member(get_value(<<"id">>, RowProps), Ids) of true -> - {queue:in(Row, Rows), Count + 1}; + maybe_queue_row(Row, State); false -> {Rows, Count} end. + +maybe_queue_row({Props} = Row, #state{count = Count, rows = Rows} = State) -> + case get_value(<<"id">>, Props) of + <<>> -> + [_, Db | _] = State#state.init_args, + ?LOG_ERROR("Replicator: ignoring document with empty ID in source " + "database `~s` (_changes sequence ~p)", + [dbname(Db), couch_util:get_value(<<"seq">>, Props)]), + {Rows, Count}; + _ -> + {queue:in(Row, Rows), Count + 1} + end. + +dbname(#http_db{url = Url}) -> + couch_util:url_strip_password(Url); +dbname(#db{name = Name}) -> + Name. -- cgit v1.2.3 From e77949221f63a011787118637cb549abfbd8e5e8 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sat, 1 Oct 2011 03:20:05 +0000 Subject: fix COUCHDB-648 - _update handler ignores "code" Test by Christian Carter This is a backport of r1177890 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1177892 13f79535-47bb-0310-9956-ffa450edef68 --- THANKS | 1 + share/www/script/test/update_documents.js | 24 ++++++++++++++++++++++++ src/couchdb/couch_httpd_show.erl | 16 +++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/THANKS b/THANKS index 76a0c19b..470c3937 100644 --- a/THANKS +++ b/THANKS @@ -82,5 +82,6 @@ suggesting improvements or submitting changes. Some of these people are: * Caolan McMahon * Alexander Shorin * Christopher Bonhage + * Christian Carter For a list of authors see the `AUTHORS` file. diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js index 4d2b29fc..59af4597 100644 --- a/share/www/script/test/update_documents.js +++ b/share/www/script/test/update_documents.js @@ -75,6 +75,17 @@ couchTests.update_documents = function(debug) { }), "get-uuid" : stringFun(function(doc, req) { return [null, req.uuid]; + }), + "code-n-bump" : stringFun(function(doc,req) { + if (!doc.counter) doc.counter = 0; + doc.counter += 1; + var message = "

bumped it!

"; + resp = {"code": 302, "body": message} + return [doc, resp]; + }), + "resp-code" : stringFun(function(doc,req) { + resp = {"code": 302} + return [null, resp]; }) } }; @@ -179,4 +190,17 @@ couchTests.update_documents = function(debug) { var doc = db.open("with/slash"); TEquals(2, doc.counter, "counter should be 2"); + + // COUCHDB-648 - the code in the JSON response should be honored + + xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/code-n-bump/"+docid, { + headers : {"X-Couch-Full-Commit":"true"} + }); + T(xhr.status == 302); + T(xhr.responseText == "

bumped it!

"); + doc = db.open(docid); + T(doc.counter == 3); + + xhr = CouchDB.request("POST", "/test_suite_db/_design/update/_update/resp-code/"); + T(xhr.status == 302); }; diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index 742b0f20..58f046e4 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -127,7 +127,7 @@ handle_doc_update_req(Req, _Db, _DDoc) -> send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) -> JsonReq = couch_httpd_external:json_req_obj(Req, Db, DocId), JsonDoc = couch_query_servers:json_doc(Doc), - {Code, JsonResp1} = case couch_query_servers:ddoc_prompt(DDoc, + JsonResp1 = case couch_query_servers:ddoc_prompt(DDoc, [<<"updates">>, UpdateName], [JsonDoc, JsonReq]) of [<<"up">>, {NewJsonDoc}, {JsonResp}] -> Options = case couch_httpd:header_value(Req, "X-Couch-Full-Commit", @@ -140,16 +140,14 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) -> NewDoc = couch_doc:from_json_obj({NewJsonDoc}), {ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options), NewRevStr = couch_doc:rev_to_str(NewRev), - JsonRespWithRev = {[{<<"headers">>, - {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]}, - {201, JsonRespWithRev}; - [<<"up">>, _Other, JsonResp] -> - {200, JsonResp} + {[{<<"code">>, 201}, {<<"headers">>, + {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]}; + [<<"up">>, _Other, {JsonResp}] -> + {[{<<"code">>, 200} | JsonResp]} end, - - JsonResp2 = couch_util:json_apply_field({<<"code">>, Code}, JsonResp1), + % todo set location field - couch_httpd_external:send_external_response(Req, JsonResp2). + couch_httpd_external:send_external_response(Req, JsonResp1). % view-list request with view and list from same design doc. -- cgit v1.2.3