couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [14/50] couchdb commit: updated refs/heads/1963-eunit to bfb7eb9
Date Mon, 16 Jun 2014 22:52:55 GMT
Port 100-ref-counter.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/fad32ab9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fad32ab9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fad32ab9

Branch: refs/heads/1963-eunit
Commit: fad32ab98af0abde6ea01694136ee1f79844f914
Parents: 9227502
Author: Alexander Shorin <kxepal@apache.org>
Authored: Mon May 26 20:59:45 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Mon Jun 16 00:51:18 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am                 |   1 +
 test/couchdb/couch_ref_counter_tests.erl | 107 ++++++++++++++++++++++++
 test/etap/100-ref-counter.t              | 114 --------------------------
 test/etap/Makefile.am                    |   1 -
 4 files changed, 108 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/fad32ab9/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 53ae21d..59a366c 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -27,6 +27,7 @@ eunit_files = \
     couch_doc_json_tests.erl \
     couch_file_tests.erl \
     couch_key_tree_tests.erl \
+    couch_ref_counter_tests.erl \
     couch_stream_tests.erl \
     couch_task_status_tests.erl \
     couch_util_tests.erl \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/fad32ab9/test/couchdb/couch_ref_counter_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_ref_counter_tests.erl b/test/couchdb/couch_ref_counter_tests.erl
new file mode 100644
index 0000000..b7e97b4
--- /dev/null
+++ b/test/couchdb/couch_ref_counter_tests.erl
@@ -0,0 +1,107 @@
+% 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(couch_ref_counter_tests).
+
+-include("couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(TIMEOUT, 1000).
+
+
+setup() ->
+    {ok, RefCtr} = couch_ref_counter:start([]),
+    ChildPid = spawn(fun() -> loop() end),
+    {RefCtr, ChildPid}.
+
+teardown({_, ChildPid}) ->
+    erlang:monitor(process, ChildPid),
+    ChildPid ! close,
+    wait().
+
+
+couch_ref_counter_test_() ->
+    {
+        "CouchDB reference counter tests",
+        {
+            foreach,
+            fun setup/0, fun teardown/1,
+            [
+                fun should_initialize_with_calling_process_as_referrer/1,
+                fun should_ignore_unknown_pid/1,
+                fun should_increment_counter_on_pid_add/1,
+                fun should_not_increase_counter_on_readding_same_pid/1,
+                fun should_drop_ref_for_double_added_pid/1,
+                fun should_decrement_counter_on_pid_drop/1,
+                fun should_add_after_drop/1,
+                fun should_decrement_counter_on_process_exit/1
+
+            ]
+        }
+    }.
+
+
+should_initialize_with_calling_process_as_referrer({RefCtr, _}) ->
+    ?_assertEqual(1, couch_ref_counter:count(RefCtr)).
+
+should_ignore_unknown_pid({RefCtr, ChildPid}) ->
+    ?_assertEqual(ok, couch_ref_counter:drop(RefCtr, ChildPid)).
+
+should_increment_counter_on_pid_add({RefCtr, ChildPid}) ->
+    couch_ref_counter:add(RefCtr, ChildPid),
+    ?_assertEqual(2, couch_ref_counter:count(RefCtr)).
+
+should_not_increase_counter_on_readding_same_pid({RefCtr, ChildPid}) ->
+    couch_ref_counter:add(RefCtr, ChildPid),
+    couch_ref_counter:add(RefCtr, ChildPid),
+    ?_assertEqual(2, couch_ref_counter:count(RefCtr)).
+
+should_drop_ref_for_double_added_pid({RefCtr, ChildPid}) ->
+    couch_ref_counter:add(RefCtr, ChildPid),
+    couch_ref_counter:add(RefCtr, ChildPid),
+    couch_ref_counter:drop(RefCtr, ChildPid),
+    ?_assertEqual(2, couch_ref_counter:count(RefCtr)).
+
+should_decrement_counter_on_pid_drop({RefCtr, ChildPid}) ->
+    couch_ref_counter:add(RefCtr, ChildPid),
+    couch_ref_counter:drop(RefCtr, ChildPid),
+    ?_assertEqual(1, couch_ref_counter:count(RefCtr)).
+
+should_add_after_drop({RefCtr, ChildPid}) ->
+    couch_ref_counter:add(RefCtr, ChildPid),
+    couch_ref_counter:drop(RefCtr, ChildPid),
+    couch_ref_counter:add(RefCtr, ChildPid),
+    ?_assertEqual(2, couch_ref_counter:count(RefCtr)).
+
+should_decrement_counter_on_process_exit({RefCtr, ChildPid}) ->
+    ?_assertEqual(1,
+        begin
+            couch_ref_counter:add(RefCtr, ChildPid),
+            erlang:monitor(process, ChildPid),
+            ChildPid ! close,
+            wait(),
+            couch_ref_counter:count(RefCtr)
+        end).
+
+
+loop() ->
+    receive
+        close -> ok
+    end.
+
+wait() ->
+    receive
+        {'DOWN', _, _, _, _} ->
+            ok
+    after ?TIMEOUT ->
+        throw(timeout_error)
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/fad32ab9/test/etap/100-ref-counter.t
----------------------------------------------------------------------
diff --git a/test/etap/100-ref-counter.t b/test/etap/100-ref-counter.t
deleted file mode 100755
index 8f996d0..0000000
--- a/test/etap/100-ref-counter.t
+++ /dev/null
@@ -1,114 +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(8),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-loop() ->
-    receive
-        close -> ok
-    end.
-
-wait() ->
-    receive
-        {'DOWN', _, _, _, _} -> ok
-    after 1000 ->
-        throw(timeout_error)
-    end.
-
-test() ->
-    {ok, RefCtr} = couch_ref_counter:start([]),
-
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        1,
-        "A ref_counter is initialized with the calling process as a referer."
-    ),
-
-    ChildPid1 = spawn(fun() -> loop() end),
-
-    % This is largely implicit in that nothing else breaks
-    % as ok is just returned from gen_server:cast()
-    etap:is(
-        couch_ref_counter:drop(RefCtr, ChildPid1),
-        ok,
-        "Dropping an unknown Pid is ignored."
-    ),
-
-    couch_ref_counter:add(RefCtr, ChildPid1),
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        2,
-        "Adding a Pid to the ref_counter increases it's count."
-    ),
-
-    couch_ref_counter:add(RefCtr, ChildPid1),
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        2,
-        "Readding the same Pid maintains the count but increments it's refs."
-    ),
-
-    couch_ref_counter:drop(RefCtr, ChildPid1),
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        2,
-        "Droping the doubly added Pid only removes a ref, not a referer."
-    ),
-
-    couch_ref_counter:drop(RefCtr, ChildPid1),
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        1,
-        "Dropping the second ref drops the referer."
-    ),
-
-    couch_ref_counter:add(RefCtr, ChildPid1),
-    etap:is(
-        couch_ref_counter:count(RefCtr),
-        2,
-        "Sanity checking that the Pid was re-added."
-    ),
-
-    erlang:monitor(process, ChildPid1),
-    ChildPid1 ! close,
-    wait(),
-    
-    CheckFun = fun
-        (Iter, nil) ->
-            case couch_ref_counter:count(RefCtr) of
-                1 -> Iter;
-                _ -> nil
-            end;
-        (_, Acc) ->
-            Acc
-    end,
-    Result = lists:foldl(CheckFun, nil, lists:seq(1, 10000)),
-    etap:isnt(
-        Result,
-        nil,
-        "The referer count was decremented automatically on process exit."
-    ),
-
-    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/fad32ab9/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 4657656..2e38ee5 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,7 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    100-ref-counter.t \
     120-stats-collect.t \
     121-stats-aggregates.cfg \
     121-stats-aggregates.ini \


Mime
View raw message