You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/03/03 23:06:06 UTC

[couchdb] branch fix-chttpd-socket-buffer-size-test-2.3.x created (now 8835e3f)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch fix-chttpd-socket-buffer-size-test-2.3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 8835e3f  Improve chttpd_socket_buffer_size_test

This branch includes the following new commits:

     new 8835e3f  Improve chttpd_socket_buffer_size_test

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Improve chttpd_socket_buffer_size_test

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-chttpd-socket-buffer-size-test-2.3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8835e3f134bbbc8aee0ae89ac23d288614fc8ba2
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sun Mar 3 17:02:28 2019 -0500

    Improve chttpd_socket_buffer_size_test
    
    Previously this test used to fail on Windows, possibly to due to a full restart
    of the chttp and mochiweb applications. It turns out chttpd monitors config
    changes and restarts the listner if there any change which affect the listening
    socket. One issue with this approach is that restart intensity is limited to 3
    times in 10 seconds. To avoid this usue, some redundant tests were removed. The
    three tests which are left should cover the same functionality as before,
    namely:
    
     1) In the default case, a large enough (7KB) url and header should be parsed.
    
     2) Manually setting `buffer` works and will reduce the maximum header line
     length and then the server should return a 400 error.
    
     3) Setting `recbuf` also sets the user land `buffer` value as well with the
     same effect as 2).
---
 src/chttpd/test/chttpd_socket_buffer_size_test.erl | 81 +++++++++-------------
 1 file changed, 33 insertions(+), 48 deletions(-)

diff --git a/src/chttpd/test/chttpd_socket_buffer_size_test.erl b/src/chttpd/test/chttpd_socket_buffer_size_test.erl
index 650bf9b..0ac7f03 100644
--- a/src/chttpd/test/chttpd_socket_buffer_size_test.erl
+++ b/src/chttpd/test/chttpd_socket_buffer_size_test.erl
@@ -21,19 +21,24 @@
 -define(CONTENT_JSON, {"Content-Type", "application/json"}).
 
 
+% Note: these tests reconfigure chttpd. When it reconfigures it, chttpd will
+% restart to pick up the new settings. However, the default restart intensity
+% is 3 times in 10 seconds so avoid adding too many settings updates. Also this
+% test is apprently more flaky on Windows for some reason.
+
+
 setup() ->
     Hashed = couch_passwords:hash_admin_password(?PASS),
     ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
     SocketOptions = config:get("chttpd", "socket_options"),
     Db = ?tempdb(),
-    Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
-    Port = integer_to_list(mochiweb_socket_server:get(chttpd, port)),
-    Url = "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(Db),
-    create_db(Url),
+    create_db(url(Db)),
+    meck:new(mochiweb_socket_server, [passthrough]),
     {Db, SocketOptions}.
 
 
 teardown({Db, SocketOptions}) ->
+    meck:unload(),
     delete_db(url(Db)),
     ok = config:delete("chttpd", "socket_options", _Persist=false),
     ok = config:delete("admins", ?USER, _Persist=false),
@@ -57,9 +62,7 @@ socket_buffer_size_test_() ->
                 fun setup/0, fun teardown/1,
                 [
                     fun buffer_too_small_url_fails/1,
-                    fun buffer_too_small_header_fails/1,
                     fun recbuf_too_small_url_fails/1,
-                    fun recbuf_too_small_header_fails/1,
                     fun default_buffer_settings_work/1
                 ]
             }
@@ -69,55 +72,25 @@ socket_buffer_size_test_() ->
 
 buffer_too_small_url_fails({Db, _}) ->
     ?_test(begin
-        restart_chttpd("[{buffer, 1024}]"),
+        reconfigure_chttpd("[{buffer, 1024}]"),
         Id = data(1500),
         Status1 = put_req(url(Db) ++ "/" ++ Id, "{}"),
-        ?assertEqual(400, Status1),
-        restart_chttpd("[{buffer, 2048}]"),
-        Status2 = put_req(url(Db) ++ "/" ++ Id, "{}"),
-        ?assert(Status2 =:= 201 orelse Status2 =:= 202)
-    end).
-
-
-buffer_too_small_header_fails({Db, _}) ->
-    ?_test(begin
-        restart_chttpd("[{buffer, 1024}]"),
-        Headers = [{"Blah", data(1500)}],
-        Status1 = put_req(url(Db) ++ "/d", Headers, "{}"),
-        ?assertEqual(400, Status1),
-        restart_chttpd("[{buffer, 2048}]"),
-        Status2 = put_req(url(Db) ++ "/d", Headers, "{}"),
-        ?assert(Status2 =:= 201 orelse Status2 =:= 202)
+        ?assertEqual(400, Status1)
     end).
 
 
 recbuf_too_small_url_fails({Db, _}) ->
     ?_test(begin
-        restart_chttpd("[{recbuf, 1024}]"),
+        reconfigure_chttpd("[{recbuf, 1024}]"),
         Id = data(1500),
         Status1 = put_req(url(Db) ++ "/" ++ Id, "{}"),
-        ?assertEqual(400, Status1),
-        restart_chttpd("[{recbuf, 2048}]"),
-        Status2 = put_req(url(Db) ++ "/" ++ Id, "{}"),
-        ?assert(Status2 =:= 201 orelse Status2 =:= 202)
-    end).
-
-
-recbuf_too_small_header_fails({Db, _}) ->
-    ?_test(begin
-        restart_chttpd("[{recbuf, 1024}]"),
-        Headers = [{"Blah", data(1500)}],
-        Status1 = put_req(url(Db) ++ "/d", Headers, "{}"),
-        ?assertEqual(400, Status1),
-        restart_chttpd("[{recbuf, 2048}]"),
-        Status2 = put_req(url(Db) ++ "/d", Headers, "{}"),
-        ?assert(Status2 =:= 201 orelse Status2 =:= 202)
+        ?assertEqual(400, Status1)
     end).
 
 
 default_buffer_settings_work({Db, _}) ->
     ?_test(begin
-        restart_chttpd("[{recbuf, undefined}]"),
+        reconfigure_chttpd("[{recbuf, undefined}]"),
         Id = data(7000),
         Status = put_req(url(Db) ++ "/" ++ Id, "{}"),
         ?assert(Status =:= 201 orelse Status =:= 202)
@@ -126,10 +99,14 @@ default_buffer_settings_work({Db, _}) ->
 
 % Helper functions
 
-url(Db) ->
+url() ->
     Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
     Port = integer_to_list(mochiweb_socket_server:get(chttpd, port)),
-    "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(Db).
+    "http://" ++ Addr ++ ":" ++ Port.
+
+
+url(Db) ->
+    url() ++ "/" ++ ?b2l(Db).
 
 
 create_db(Url) ->
@@ -155,9 +132,17 @@ data(Size) ->
     string:copies("x", Size).
 
 
-restart_chttpd(ServerOptions) ->
-    ok = application:stop(chttpd),
-    ok = application:stop(mochiweb),
+reconfigure_chttpd(ServerOptions) ->
+    meck:reset(mochiweb_socket_server),
     config:set("chttpd", "server_options", ServerOptions, _Persist=false),
-    ok = application:start(mochiweb),
-    ok = application:start(chttpd).
+    meck:wait(mochiweb_socket_server, init, '_', 10000),
+    test_util:wait(fun() ->
+        try
+            case test_request:get(url(), [?AUTH]) of
+                {ok, 200, _, _} -> ok;
+                _ -> wait
+            end
+        catch _:_ ->
+                wait
+        end
+   end).