You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/04/18 16:34:43 UTC

[couchdb] branch COUCHDB-3376-fix-mem3-shards updated: Tweak mem3_shard test contrbutions

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

davisp pushed a commit to branch COUCHDB-3376-fix-mem3-shards
in repository https://gitbox.apache.org/repos/asf/couchdb.git

The following commit(s) were added to refs/heads/COUCHDB-3376-fix-mem3-shards by this push:
       new  48536fb   Tweak mem3_shard test contrbutions
48536fb is described below

commit 48536fb00ec1e5a78b417d00bcf52c907adca0c7
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Apr 18 11:33:25 2017 -0500

    Tweak mem3_shard test contrbutions
    
    This chang is just to make the shard map assertions a bit more obvious
    so that we're not relying on `mock_shards/0` to return a constant.
    
    COUCHDB-3376
---
 src/mem3/src/mem3_shards.erl | 51 ++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl
index 5cdbc6c..0e16db6 100644
--- a/src/mem3/src/mem3_shards.erl
+++ b/src/mem3/src/mem3_shards.erl
@@ -508,8 +508,6 @@ filter_shards_by_name(Name, Matches, [_|Ss]) ->
     filter_shards_by_name(Name, Matches, Ss).
 
 
-% Export all functions for unit tests
-
 -ifdef(TEST).
 
 -include_lib("eunit/include/eunit.hrl").
@@ -573,15 +571,16 @@ t_maybe_spawn_shard_writer_new() ->
         ?assert(is_process_alive(WPid)),
         WPid ! write,
         ?assertEqual(normal, wait_writer_result(WRef)),
-        ?assertEqual(mock_shards(), ets:tab2list(?SHARDS))
+        ?assertEqual(Shards, ets:tab2list(?SHARDS))
     end).
 
 
 t_flush_writer_exists_normal() ->
     ?_test(begin
-        WPid = spawn_link_mock_writer(?INFINITY),
+        Shards = mock_shards(),
+        WPid = spawn_link_mock_writer(?DB, Shards, ?INFINITY),
         ?assertEqual(ok, flush_write(?DB, WPid, ?INFINITY)),
-        ?assertEqual(mock_shards(), ets:tab2list(?SHARDS))
+        ?assertEqual(Shards, ets:tab2list(?SHARDS))
     end).
 
 
@@ -604,25 +603,27 @@ t_flush_writer_crashes() ->
 
 t_writer_deletes_itself_when_done() ->
     ?_test(begin
-        WPid = spawn_link_mock_writer(?INFINITY),
+        Shards = mock_shards(),
+        WPid = spawn_link_mock_writer(?DB, Shards, ?INFINITY),
         WRef = erlang:monitor(process, WPid),
         ets:insert(?OPENERS, {?DB, WPid}),
         WPid ! write,
         ?assertEqual(normal, wait_writer_result(WRef)),
-        ?assertEqual(mock_shards(), ets:tab2list(?SHARDS)),
+        ?assertEqual(Shards, ets:tab2list(?SHARDS)),
         ?assertEqual([], ets:tab2list(?OPENERS))
     end).
 
 
 t_writer_does_not_delete_other_writers_for_same_shard() ->
     ?_test(begin
-        WPid = spawn_link_mock_writer(?INFINITY),
+        Shards = mock_shards(),
+        WPid = spawn_link_mock_writer(?DB, Shards, ?INFINITY),
         WRef = erlang:monitor(process, WPid),
         ets:insert(?OPENERS, {?DB, WPid}),
         ets:insert(?OPENERS, {?DB, self()}),  % should not be deleted
         WPid ! write,
         ?assertEqual(normal, wait_writer_result(WRef)),
-        ?assertEqual(mock_shards(), ets:tab2list(?SHARDS)),
+        ?assertEqual(Shards, ets:tab2list(?SHARDS)),
         ?assertEqual(1, ets:info(?OPENERS, size)),
         ?assertEqual([{?DB, self()}], ets:tab2list(?OPENERS))
     end).
@@ -651,18 +652,20 @@ t_spawn_writer_in_load_shards_from_db() ->
 
 t_cache_insert_takes_new_update() ->
     ?_test(begin
-        WPid = spawn_link_mock_writer(?INFINITY),
+        Shards = mock_shards(),
+        WPid = spawn_link_mock_writer(?DB, Shards, ?INFINITY),
         Msg = {cache_insert, ?DB, WPid, 2},
         {noreply, NewState} = handle_cast(Msg, mock_state(1)),
         ?assertMatch(#st{cur_size = 1}, NewState),
-        ?assertEqual(mock_shards(), ets:tab2list(?SHARDS)),
+        ?assertEqual(Shards, ets:tab2list(?SHARDS)),
         ?assertEqual([], ets:tab2list(?OPENERS))
     end).
 
 
 t_cache_insert_ignores_stale_update_and_kills_worker() ->
     ?_test(begin
-        WPid = spawn_link_mock_writer(?INFINITY),
+        Shards = mock_shards(),
+        WPid = spawn_link_mock_writer(?DB, Shards, ?INFINITY),
         WRef = erlang:monitor(process, WPid),
         Msg = {cache_insert, ?DB, WPid, 1},
         {noreply, NewState} = handle_cast(Msg, mock_state(2)),
@@ -674,7 +677,10 @@ t_cache_insert_ignores_stale_update_and_kills_worker() ->
 
 
 mock_state(UpdateSeq) ->
-    #st{changes_pid = self(), update_seq = UpdateSeq}.
+    #st{
+        update_seq = UpdateSeq,
+        changes_pid = self()
+    }.
 
 
 mock_shards() ->
@@ -698,9 +704,22 @@ wait_writer_result(WRef) ->
     end.
 
 
-spawn_link_mock_writer(Timeout) ->
-    Shards = mock_shards(),
-    erlang:spawn_link(fun() -> shard_writer(?DB, Shards, Timeout) end).
+spawn_link_mock_writer(Db, Shards, Timeout) ->
+    erlang:spawn_link(fun() -> shard_writer(Db, Shards, Timeout) end).
+
+
+mock_changes_listener() ->
+    Self = self(),
+    erlang:spawn(fun() ->
+        Ref = erlang:monitor(process, Self),
+        mock_changes_listener_loop(Self, Ref)
+    end).
+
+
+mock_changes_listener_loop(Pid, Ref) ->
+    receive
+        {'DOWN', Ref, process, Pid, _} -> ok
+    end.
 
 
 -endif.

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].