diff options
-rwxr-xr-x | test/etap/030-doc-from-json.t | 5 | ||||
-rwxr-xr-x | test/etap/031-doc-to-json.t | 5 | ||||
-rwxr-xr-x | test/etap/070-couch-db.t | 4 | ||||
-rwxr-xr-x | test/etap/110-replication-httpc.t | 14 | ||||
-rwxr-xr-x | test/etap/111-replication-changes-feed.t | 15 | ||||
-rwxr-xr-x | test/etap/112-replication-missing-revs.t | 12 | ||||
-rwxr-xr-x | test/etap/113-replication-attachment-comp.t | 7 | ||||
-rwxr-xr-x | test/etap/130-attachments-md5.t | 8 | ||||
-rwxr-xr-x | test/etap/140-attachment-comp.t | 7 | ||||
-rwxr-xr-x | test/etap/150-invalid-view-seq.t | 10 | ||||
-rwxr-xr-x | test/etap/160-vhosts.t | 17 | ||||
-rwxr-xr-x | test/etap/173-os-daemon-cfg-register.t | 7 | ||||
-rw-r--r-- | test/etap/180-http-proxy.ini | 4 | ||||
-rwxr-xr-x | test/etap/180-http-proxy.t | 43 | ||||
-rw-r--r-- | test/etap/random_port.ini | 19 | ||||
-rw-r--r-- | test/etap/test_util.erl.in | 8 | ||||
-rw-r--r-- | test/etap/test_web.erl | 2 |
17 files changed, 106 insertions, 81 deletions
diff --git a/test/etap/030-doc-from-json.t b/test/etap/030-doc-from-json.t index c4ef649a..1090fc38 100755 --- a/test/etap/030-doc-from-json.t +++ b/test/etap/030-doc-from-json.t @@ -20,9 +20,6 @@ -record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data, encoding=identity}). -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - main(_) -> test_util:init_code_path(), etap:plan(26), @@ -36,7 +33,7 @@ main(_) -> ok. test() -> - couch_config:start_link([default_config()]), + couch_config:start_link(test_util:config_files()), couch_config:set("attachments", "compression_level", "0"), ok = test_from_json_success(), ok = test_from_json_errors(), diff --git a/test/etap/031-doc-to-json.t b/test/etap/031-doc-to-json.t index 605a6d00..4deeb0f2 100755 --- a/test/etap/031-doc-to-json.t +++ b/test/etap/031-doc-to-json.t @@ -20,9 +20,6 @@ -record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data, encoding=identity}). -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - main(_) -> test_util:init_code_path(), etap:plan(12), @@ -36,7 +33,7 @@ main(_) -> ok. test() -> - couch_config:start_link([default_config()]), + couch_config:start_link(test_util:config_files()), couch_config:set("attachments", "compression_level", "0"), ok = test_to_json_success(), ok. diff --git a/test/etap/070-couch-db.t b/test/etap/070-couch-db.t index 4b14aba6..787d6c6a 100755 --- a/test/etap/070-couch-db.t +++ b/test/etap/070-couch-db.t @@ -28,9 +28,7 @@ main(_) -> test() -> - couch_server_sup:start_link( - ["etc/couchdb/default_dev.ini", "etc/couchdb/local_dev.ini"] - ), + couch_server_sup:start_link(test_util:config_files()), couch_db:create(<<"etap-test-db">>, []), {ok, AllDbs} = couch_server:all_databases(), diff --git a/test/etap/110-replication-httpc.t b/test/etap/110-replication-httpc.t index 529239c5..39b0755e 100755 --- a/test/etap/110-replication-httpc.t +++ b/test/etap/110-replication-httpc.t @@ -35,15 +35,13 @@ conn = nil }). -server() -> "http://127.0.0.1:5984/". -dbname() -> "etap-test-db". - -config_files() -> - lists:map(fun test_util:build_file/1, [ - "etc/couchdb/default_dev.ini", - "etc/couchdb/local_dev.ini" +server() -> + lists:concat([ + "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/" ]). +dbname() -> "etap-test-db". + main(_) -> test_util:init_code_path(), @@ -58,7 +56,7 @@ main(_) -> ok. test() -> - couch_server_sup:start_link(config_files()), + couch_server_sup:start_link(test_util:config_files()), ibrowse:start(), crypto:start(), diff --git a/test/etap/111-replication-changes-feed.t b/test/etap/111-replication-changes-feed.t index 778b99dd..358bf1e2 100755 --- a/test/etap/111-replication-changes-feed.t +++ b/test/etap/111-replication-changes-feed.t @@ -38,12 +38,6 @@ conn = nil }). -config_files() -> - lists:map(fun test_util:build_file/1, [ - "etc/couchdb/default_dev.ini", - "etc/couchdb/local_dev.ini" - ]). - main(_) -> test_util:init_code_path(), @@ -58,7 +52,7 @@ main(_) -> ok. test() -> - couch_server_sup:start_link(config_files()), + couch_server_sup:start_link(test_util:config_files()), ibrowse:start(), crypto:start(), @@ -237,7 +231,12 @@ get_db() -> get_dbname(local) -> "etap-test-db"; get_dbname(remote) -> - "http://127.0.0.1:5984/etap-test-db/". + server() ++ "etap-test-db/". + +server() -> + lists:concat([ + "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/" + ]). get_update_seq() -> Db = get_db(), diff --git a/test/etap/112-replication-missing-revs.t b/test/etap/112-replication-missing-revs.t index 71971088..ebaa05ed 100755 --- a/test/etap/112-replication-missing-revs.t +++ b/test/etap/112-replication-missing-revs.t @@ -42,7 +42,8 @@ config_files() -> lists:map(fun test_util:build_file/1, [ "etc/couchdb/default_dev.ini", - "etc/couchdb/local_dev.ini" + "etc/couchdb/local_dev.ini", + "test/etap/random_port.ini" ]). main(_) -> @@ -185,9 +186,14 @@ start_changes_feed(local, Since, Continuous) -> couch_rep_changes_feed:start_link(self(), get_db(source), Since, Props); start_changes_feed(remote, Since, Continuous) -> Props = [{<<"continuous">>, Continuous}], - Db = #http_db{url = "http://127.0.0.1:5984/etap-test-source/"}, + Db = #http_db{url = server() ++ "etap-test-source/"}, couch_rep_changes_feed:start_link(self(), Db, Since, Props). +server() -> + lists:concat([ + "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/" + ]). + couch_rep_pid(Db) -> spawn(fun() -> couch_rep_pid_loop(Db) end). @@ -203,6 +209,6 @@ start_missing_revs(local, Changes) -> MainPid = couch_rep_pid(TargetDb), couch_rep_missing_revs:start_link(MainPid, TargetDb, Changes, []); start_missing_revs(remote, Changes) -> - TargetDb = #http_db{url = "http://127.0.0.1:5984/etap-test-target/"}, + TargetDb = #http_db{url = server() ++ "etap-test-target/"}, MainPid = couch_rep_pid(TargetDb), couch_rep_missing_revs:start_link(MainPid, TargetDb, Changes, []). diff --git a/test/etap/113-replication-attachment-comp.t b/test/etap/113-replication-attachment-comp.t index 19c48fc6..1f2b63f2 100755 --- a/test/etap/113-replication-attachment-comp.t +++ b/test/etap/113-replication-attachment-comp.t @@ -19,9 +19,6 @@ handler }). -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - test_db_a_name() -> <<"couch_test_rep_att_comp_a">>. @@ -41,9 +38,9 @@ main(_) -> ok. test() -> - couch_server_sup:start_link([default_config()]), + couch_server_sup:start_link(test_util:config_files()), put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")), - put(port, couch_config:get("httpd", "port", "5984")), + put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), application:start(inets), ibrowse:start(), timer:sleep(1000), diff --git a/test/etap/130-attachments-md5.t b/test/etap/130-attachments-md5.t index 4c40f83a..6296e08a 100755 --- a/test/etap/130-attachments-md5.t +++ b/test/etap/130-attachments-md5.t @@ -11,9 +11,6 @@ % License for the specific language governing permissions and limitations under % the License. -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - test_db_name() -> <<"etap-test-db">>. @@ -41,11 +38,10 @@ main(_) -> ok. test() -> - couch_server_sup:start_link([default_config()]), + couch_server_sup:start_link(test_util:config_files()), Addr = couch_config:get("httpd", "bind_address", any), - Port = list_to_integer(couch_config:get("httpd", "port", "5984")), put(addr, Addr), - put(port, Port), + put(port, mochiweb_socket_server:get(couch_httpd, port)), timer:sleep(1000), couch_server:delete(test_db_name(), []), diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t index 21922f99..bf1b21c4 100755 --- a/test/etap/140-attachment-comp.t +++ b/test/etap/140-attachment-comp.t @@ -13,9 +13,6 @@ % License for the specific language governing permissions and limitations under % the License. -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - test_db_name() -> <<"couch_test_atts_compression">>. @@ -33,9 +30,9 @@ main(_) -> ok. test() -> - couch_server_sup:start_link([default_config()]), + couch_server_sup:start_link(test_util:config_files()), put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")), - put(port, couch_config:get("httpd", "port", "5984")), + put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), application:start(inets), timer:sleep(1000), couch_server:delete(test_db_name(), []), diff --git a/test/etap/150-invalid-view-seq.t b/test/etap/150-invalid-view-seq.t index 0664c116..594d3416 100755 --- a/test/etap/150-invalid-view-seq.t +++ b/test/etap/150-invalid-view-seq.t @@ -19,9 +19,6 @@ handler }). -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - test_db_name() -> <<"couch_test_invalid_view_seq">>. @@ -42,7 +39,7 @@ main(_) -> %% a huge and ugly but harmless stack trace is sent to stderr %% test() -> - couch_server_sup:start_link([default_config()]), + couch_server_sup:start_link(test_util:config_files()), timer:sleep(1000), delete_db(), create_db(), @@ -54,7 +51,7 @@ test() -> backup_db_file(), put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")), - put(port, couch_config:get("httpd", "port", "5984")), + put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), application:start(inets), create_new_doc(), @@ -168,8 +165,9 @@ restore_backup_db_file() -> binary_to_list(test_db_name()) ++ ".couch"), ok = file:delete(DbFile), ok = file:rename(DbFile ++ ".backup", DbFile), - couch_server_sup:start_link([default_config()]), + couch_server_sup:start_link(test_util:config_files()), timer:sleep(1000), + put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), ok. query_view_after_restore_backup() -> diff --git a/test/etap/160-vhosts.t b/test/etap/160-vhosts.t index f4bd5e27..c7dc8f99 100755 --- a/test/etap/160-vhosts.t +++ b/test/etap/160-vhosts.t @@ -41,16 +41,14 @@ handler }). -server() -> "http://127.0.0.1:5984/". +server() -> + lists:concat([ + "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/" + ]). + dbname() -> "etap-test-db". admin_user_ctx() -> {user_ctx, #user_ctx{roles=[<<"_admin">>]}}. -config_files() -> - lists:map(fun test_util:build_file/1, [ - "etc/couchdb/default_dev.ini", - "etc/couchdb/local_dev.ini" - ]). - main(_) -> test_util:init_code_path(), @@ -65,7 +63,7 @@ main(_) -> ok. test() -> - couch_server_sup:start_link(config_files()), + couch_server_sup:start_link(test_util:config_files()), ibrowse:start(), crypto:start(), @@ -118,6 +116,9 @@ test() -> ok = couch_config:set("vhosts", "*/test1", "/etap-test-db/_design/doc1/_show/test", false), + % let couch_httpd restart + timer:sleep(100), + test_regular_request(), test_vhost_request(), test_vhost_request_with_qs(), diff --git a/test/etap/173-os-daemon-cfg-register.t b/test/etap/173-os-daemon-cfg-register.t index 3ee2969a..af9cbaa0 100755 --- a/test/etap/173-os-daemon-cfg-register.t +++ b/test/etap/173-os-daemon-cfg-register.t @@ -24,11 +24,6 @@ buf=[] }). -config_files() -> - lists:map(fun test_util:build_file/1, [ - "etc/couchdb/default_dev.ini" - ]). - daemon_name() -> "wheee". @@ -49,7 +44,7 @@ main(_) -> ok. test() -> - couch_config:start_link(config_files()), + couch_config:start_link(test_util:config_files()), couch_os_daemons:start_link(), DaemonCmd = daemon_cmd() ++ " 2> /dev/null", diff --git a/test/etap/180-http-proxy.ini b/test/etap/180-http-proxy.ini index 72a63f66..3e2ba137 100644 --- a/test/etap/180-http-proxy.ini +++ b/test/etap/180-http-proxy.ini @@ -15,6 +15,6 @@ ; specific language governing permissions and limitations ; under the License. +; 49151 is IANA Reserved, let's assume no one is listening there [httpd_global_handlers] -_test = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985/">>} -_error = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5986/">>}
\ No newline at end of file +_error = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:49151/">>} diff --git a/test/etap/180-http-proxy.t b/test/etap/180-http-proxy.t index cf1c2783..3d31b95a 100755 --- a/test/etap/180-http-proxy.t +++ b/test/etap/180-http-proxy.t @@ -13,14 +13,16 @@ -record(req, {method=get, path="", headers=[], body="", opts=[]}). -default_config() -> - [ - test_util:build_file("etc/couchdb/default_dev.ini"), - test_util:source_file("test/etap/180-http-proxy.ini") - ]. - -server() -> "http://127.0.0.1:5984/_test/". -proxy() -> "http://127.0.0.1:5985/". +server() -> + lists:concat([ + "http://127.0.0.1:", + mochiweb_socket_server:get(couch_httpd, port), + "/_test/" + ]). + +proxy() -> + "http://127.0.0.1:" ++ integer_to_list(test_web:get_port()) ++ "/". + external() -> "https://www.google.com/". main(_) -> @@ -65,11 +67,25 @@ check_request(Name, Req, Remote, Local) -> Resp. test() -> - couch_server_sup:start_link(default_config()), + couch_server_sup:start_link([ + test_util:build_file("test/etap/180-http-proxy.ini") | + test_util:config_files() + ]), ibrowse:start(), crypto:start(), + + % start the test_web server on a random port test_web:start_link(), - + Url = lists:concat([ + "{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:", + test_web:get_port(), + "/\">>}" + ]), + couch_config:set("httpd_global_handlers", "_test", Url, false), + + % let couch_httpd restart + timer:sleep(100), + test_basic(), test_alternate_status(), test_trailing_slash(), @@ -320,7 +336,12 @@ test_passes_chunked_body_back() -> test_connect_error() -> Local = fun({ok, "500", _Headers, _Body}) -> true; (_) -> false end, - Req = #req{opts=[{url, "http://127.0.0.1:5984/_error"}]}, + Url = lists:concat([ + "http://127.0.0.1:", + mochiweb_socket_server:get(couch_httpd, port), + "/_error" + ]), + Req = #req{opts=[{url, Url}]}, check_request("Connect error", Req, no_remote, Local). diff --git a/test/etap/random_port.ini b/test/etap/random_port.ini new file mode 100644 index 00000000..ada3c13d --- /dev/null +++ b/test/etap/random_port.ini @@ -0,0 +1,19 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. + +[httpd] +port = 0 diff --git a/test/etap/test_util.erl.in b/test/etap/test_util.erl.in index 4c42edb1..59bbc59a 100644 --- a/test/etap/test_util.erl.in +++ b/test/etap/test_util.erl.in @@ -13,7 +13,7 @@ -module(test_util). -export([init_code_path/0]). --export([source_file/1, build_file/1]). +-export([source_file/1, build_file/1, config_files/0]). srcdir() -> "@abs_top_srcdir@". @@ -33,3 +33,9 @@ source_file(Name) -> build_file(Name) -> filename:join([builddir(), Name]). +config_files() -> + lists:map(fun build_file/1, [ + "etc/couchdb/default_dev.ini", + "etc/couchdb/local_dev.ini", + "test/etap/random_port.ini" + ]). diff --git a/test/etap/test_web.erl b/test/etap/test_web.erl index 16438b31..ed78651f 100644 --- a/test/etap/test_web.erl +++ b/test/etap/test_web.erl @@ -25,7 +25,7 @@ start_link() -> mochiweb_http:start([ {name, ?SERVER}, {loop, {?MODULE, loop}}, - {port, 5985} + {port, 0} ]). loop(Req) -> |