couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [25/50] couchdb commit: updated refs/heads/1963-eunit to bfb7eb9
Date Mon, 16 Jun 2014 22:53:06 GMT
Port 210-os-proc-pool.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/bde290a2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/bde290a2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/bde290a2

Branch: refs/heads/1963-eunit
Commit: bde290a2ab2a87042421f8038e137665f9ab9e12
Parents: e32e1e9
Author: Alexander Shorin <kxepal@apache.org>
Authored: Sun Jun 8 13:08:50 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Tue Jun 17 01:41:45 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am              |   1 +
 test/couchdb/couchdb_os_proc_pool.erl | 179 +++++++++++++++++++++++++++++
 test/etap/210-os-proc-pool.t          | 163 --------------------------
 test/etap/Makefile.am                 |   1 -
 4 files changed, 180 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/bde290a2/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 6025ac6..f1728bb 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -43,6 +43,7 @@ eunit_files = \
     couchdb_http_proxy_tests.erl \
     couchdb_modules_load_tests.erl \
     couchdb_os_daemons_tests.erl \
+    couchdb_os_proc_pool.erl \
     couchdb_update_conflicts_tests.erl \
     couchdb_vhosts_tests.erl \
     couchdb_views_tests.erl \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/bde290a2/test/couchdb/couchdb_os_proc_pool.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_os_proc_pool.erl b/test/couchdb/couchdb_os_proc_pool.erl
new file mode 100644
index 0000000..1bb266e
--- /dev/null
+++ b/test/couchdb/couchdb_os_proc_pool.erl
@@ -0,0 +1,179 @@
+% Licensed 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.
+
+-module(couchdb_os_proc_pool).
+
+-include("couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(TIMEOUT, 3000).
+
+
+start() ->
+    {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN),
+    couch_config:set("query_server_config", "os_process_limit", "3", false),
+    Pid.
+
+stop(Pid) ->
+    couch_server_sup:stop(),
+    erlang:monitor(process, Pid),
+    receive
+        {'DOWN', _, _, Pid, _} ->
+            ok
+    after ?TIMEOUT ->
+        throw({timeout, server_stop})
+    end.
+
+
+os_proc_pool_test_() ->
+    {
+        "OS processes pool tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            [
+                should_block_new_proc_on_full_pool(),
+                should_free_slot_on_proc_unexpected_exit()
+            ]
+        }
+    }.
+
+
+should_block_new_proc_on_full_pool() ->
+    ?_test(begin
+        Client1 = spawn_client(),
+        Client2 = spawn_client(),
+        Client3 = spawn_client(),
+
+        ?assertEqual(ok, ping_client(Client1)),
+        ?assertEqual(ok, ping_client(Client2)),
+        ?assertEqual(ok, ping_client(Client3)),
+
+        Proc1 = get_client_proc(Client1, "1"),
+        Proc2 = get_client_proc(Client2, "2"),
+        Proc3 = get_client_proc(Client3, "3"),
+
+        ?assertNotEqual(Proc1, Proc2),
+        ?assertNotEqual(Proc2, Proc3),
+        ?assertNotEqual(Proc3, Proc1),
+
+        Client4 = spawn_client(),
+        ?assertEqual(timeout, ping_client(Client4)),
+
+        ?assertEqual(ok, stop_client(Client1)),
+        ?assertEqual(ok, ping_client(Client4)),
+
+        Proc4 = get_client_proc(Client4, "4"),
+        ?assertEqual(Proc1, Proc4),
+
+        lists:map(fun(C) ->
+            ?assertEqual(ok, stop_client(C))
+        end, [Client2, Client3, Client4])
+    end).
+
+should_free_slot_on_proc_unexpected_exit() ->
+    ?_test(begin
+        Client1 = spawn_client(),
+        Client2 = spawn_client(),
+        Client3 = spawn_client(),
+
+        ?assertEqual(ok, ping_client(Client1)),
+        ?assertEqual(ok, ping_client(Client2)),
+        ?assertEqual(ok, ping_client(Client3)),
+
+        Proc1 = get_client_proc(Client1, "1"),
+        Proc2 = get_client_proc(Client2, "2"),
+        Proc3 = get_client_proc(Client3, "3"),
+
+        ?assertNotEqual(Proc1, Proc2),
+        ?assertNotEqual(Proc2, Proc3),
+        ?assertNotEqual(Proc3, Proc1),
+
+        ?assertEqual(ok, kill_client(Client1)),
+
+        Client4 = spawn_client(),
+        ?assertEqual(ok, ping_client(Client4)),
+
+        Proc4 = get_client_proc(Client4, "4"),
+        ?assertNotEqual(Proc4, Proc1),
+        ?assertNotEqual(Proc2, Proc4),
+        ?assertNotEqual(Proc3, Proc4),
+
+        lists:map(fun(C) ->
+            ?assertEqual(ok, stop_client(C))
+        end, [Client2, Client3, Client4])
+    end).
+
+
+spawn_client() ->
+    Parent = self(),
+    Ref = make_ref(),
+    Pid = spawn(fun() ->
+        Proc = couch_query_servers:get_os_process(<<"javascript">>),
+        loop(Parent, Ref, Proc)
+    end),
+    {Pid, Ref}.
+
+ping_client({Pid, Ref}) ->
+    Pid ! ping,
+    receive
+        {pong, Ref} ->
+            ok
+    after ?TIMEOUT ->
+        timeout
+    end.
+
+get_client_proc({Pid, Ref}, ClientName) ->
+    Pid ! get_proc,
+    receive
+        {proc, Ref, Proc} -> Proc
+    after ?TIMEOUT ->
+        erlang:error({assertion_failed,
+                     [{module, ?MODULE},
+                      {line, ?LINE},
+                      {reason, "Timeout getting client "
+                               ++ ClientName ++ " proc"}]})
+    end.
+
+stop_client({Pid, Ref}) ->
+    Pid ! stop,
+    receive
+        {stop, Ref} ->
+            ok
+    after ?TIMEOUT ->
+        timeout
+    end.
+
+kill_client({Pid, Ref}) ->
+    Pid ! die,
+    receive
+        {die, Ref} ->
+            ok
+    after ?TIMEOUT ->
+        timeout
+    end.
+
+loop(Parent, Ref, Proc) ->
+    receive
+        ping ->
+            Parent ! {pong, Ref},
+            loop(Parent, Ref, Proc);
+        get_proc  ->
+            Parent ! {proc, Ref, Proc},
+            loop(Parent, Ref, Proc);
+        stop ->
+            couch_query_servers:ret_os_process(Proc),
+            Parent ! {stop, Ref};
+        die ->
+            Parent ! {die, Ref},
+            exit(some_error)
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/bde290a2/test/etap/210-os-proc-pool.t
----------------------------------------------------------------------
diff --git a/test/etap/210-os-proc-pool.t b/test/etap/210-os-proc-pool.t
deleted file mode 100755
index d80707e..0000000
--- a/test/etap/210-os-proc-pool.t
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-% Licensed 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.
-
-main(_) ->
-    test_util:init_code_path(),
-
-    etap:plan(21),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-
-test() ->
-    couch_server_sup:start_link(test_util:config_files()),
-    couch_config:set("query_server_config", "os_process_limit", "3", false),
-
-    test_pool_full(),
-    test_client_unexpected_exit(),
-
-    couch_server_sup:stop(),
-    ok.
-
-
-test_pool_full() ->
-    Client1 = spawn_client(),
-    Client2 = spawn_client(),
-    Client3 = spawn_client(),
-
-    etap:diag("Check that we can spawn the max number of processes."),
-    etap:is(ping_client(Client1), ok, "Client 1 started ok."),
-    etap:is(ping_client(Client2), ok, "Client 2 started ok."),
-    etap:is(ping_client(Client3), ok, "Client 3 started ok."),
-
-    Proc1 = get_client_proc(Client1, "1"),
-    Proc2 = get_client_proc(Client2, "2"),
-    Proc3 = get_client_proc(Client3, "3"),
-    etap:isnt(Proc1, Proc2, "Clients 1 and 2 got different procs."),
-    etap:isnt(Proc2, Proc3, "Clients 2 and 3 got different procs."),
-    etap:isnt(Proc1, Proc3, "Clients 1 and 3 got different procs."),
-
-    etap:diag("Check that client 4 blocks waiting for a process."),
-    Client4 = spawn_client(),
-    etap:is(ping_client(Client4), timeout, "Client 4 blocked while waiting."),
-
-    etap:diag("Check that stopping a client gives up its process."),
-    etap:is(stop_client(Client1), ok, "First client stopped."),
-
-    etap:diag("And check that our blocked process has been unblocked."),
-    etap:is(ping_client(Client4), ok, "Client was unblocked."),
-
-    Proc4 = get_client_proc(Client4, "4"),
-    etap:is(Proc4, Proc1, "Client 4 got proc that client 1 got before."),
-
-    lists:map(fun(C) -> ok = stop_client(C) end, [Client2, Client3, Client4]).
-
-
-test_client_unexpected_exit() ->
-    Client1 = spawn_client(),
-    Client2 = spawn_client(),
-    Client3 = spawn_client(),
-
-    etap:diag("Check that up to os_process_limit clients started."),
-    etap:is(ping_client(Client1), ok, "Client 1 started ok."),
-    etap:is(ping_client(Client2), ok, "Client 2 started ok."),
-    etap:is(ping_client(Client3), ok, "Client 3 started ok."),
-
-    Proc1 = get_client_proc(Client1, "1"),
-    Proc2 = get_client_proc(Client2, "2"),
-    Proc3 = get_client_proc(Client3, "3"),
-    etap:isnt(Proc1, Proc2, "Clients 1 and 2 got different procs."),
-    etap:isnt(Proc2, Proc3, "Clients 2 and 3 got different procs."),
-    etap:isnt(Proc1, Proc3, "Clients 1 and 3 got different procs."),
-
-    etap:diag("Check that killing a client frees an os_process."),
-    etap:is(kill_client(Client1), ok, "Client 1 died all right."),
-
-    etap:diag("Check that a new client is not blocked on boot."),
-    Client4 = spawn_client(),
-    etap:is(ping_client(Client4), ok, "New client booted without blocking."),
-
-    Proc4 = get_client_proc(Client4, "4"),
-    etap:isnt(Proc4, Proc1,
-        "Client 4 got a proc different from the one client 1 got before."),
-    etap:isnt(Proc4, Proc2, "Client 4's proc different from client 2's proc."),
-    etap:isnt(Proc4, Proc3, "Client 4's proc different from client 3's proc."),
-
-    lists:map(fun(C) -> ok = stop_client(C) end, [Client2, Client3, Client4]).
-
-
-spawn_client() ->
-    Parent = self(),
-    Ref = make_ref(),
-    Pid = spawn(fun() ->
-        Proc = couch_query_servers:get_os_process(<<"javascript">>),
-        loop(Parent, Ref, Proc)
-    end),
-    {Pid, Ref}.
-
-
-ping_client({Pid, Ref}) ->
-    Pid ! ping,
-    receive
-        {pong, Ref} -> ok
-        after 3000 -> timeout
-    end.
-
-
-get_client_proc({Pid, Ref}, ClientName) ->
-    Pid ! get_proc,
-    receive
-        {proc, Ref, Proc} -> Proc
-    after 3000 ->
-        etap:bail("Timeout getting client " ++ ClientName ++ " proc.")
-    end.
-
-
-stop_client({Pid, Ref}) ->
-    Pid ! stop,
-    receive
-        {stop, Ref} -> ok
-        after 3000 -> timeout
-    end.
-
-
-kill_client({Pid, Ref}) ->
-    Pid ! die,
-    receive
-        {die, Ref} -> ok
-        after 3000 -> timeout
-    end.
-
-
-loop(Parent, Ref, Proc) ->
-    receive
-        ping ->
-            Parent ! {pong, Ref},
-            loop(Parent, Ref, Proc);
-        get_proc  ->
-            Parent ! {proc, Ref, Proc},
-            loop(Parent, Ref, Proc);
-        stop ->
-            couch_query_servers:ret_os_process(Proc),
-            Parent ! {stop, Ref};
-        die ->
-            Parent ! {die, Ref},
-            exit(some_error)
-    end.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/bde290a2/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index c4918fa..28876d3 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -32,7 +32,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    210-os-proc-pool.t \
     220-compaction-daemon.t \
     230-pbkfd2.t \
     231-cors.t \


Mime
View raw message