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/04/01 23:41:43 UTC

[couchdb] branch reshard updated: [fixup|property_tests] add mem3 ring property test

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

vatamane pushed a commit to branch reshard
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/reshard by this push:
     new 7449d86  [fixup|property_tests] add mem3 ring property test
7449d86 is described below

commit 7449d86b050a6395206dfedd849070f219129f6b
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Mon Apr 1 19:40:24 2019 -0400

    [fixup|property_tests] add mem3 ring property test
    
    this one has connected interval plus extra intervals that don't match
    starts and ends of existing ones
---
 src/mem3/test/mem3_ring_prop_tests.erl | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/mem3/test/mem3_ring_prop_tests.erl b/src/mem3/test/mem3_ring_prop_tests.erl
index 700dc84..a2c6508 100644
--- a/src/mem3/test/mem3_ring_prop_tests.erl
+++ b/src/mem3/test/mem3_ring_prop_tests.erl
@@ -27,6 +27,19 @@ prop_get_ring_with_connected_intervals() ->
     ).
 
 
+prop_get_ring_connected_plus_random_intervals() ->
+        ?FORALL({Intervals, Extra}, {g_connected_intervals(1, 100),
+                g_random_intervals(1, 100)},
+            ?IMPLIES(sets:is_disjoint(endpoints(Intervals), endpoints(Extra)),
+                begin
+                    AllInts = Intervals ++ Extra,
+                    Ring = mem3_util:get_ring(AllInts, 1, 100),
+                    Ring =:= lists:sort(Intervals)
+                end
+            )
+        ).
+
+
 prop_get_ring_with_disconnected_intervals() ->
     ?FORALL({Start, End}, oneof(ranges()),
         ?FORALL(Intervals, g_disconnected_intervals(Start, End),
@@ -38,7 +51,7 @@ prop_get_ring_with_disconnected_intervals() ->
 % Generators
 
 ranges() ->
-    [{0,1}, {1, 10}, {0, 2 bsl 31 - 1}, {2 bsl 31 - 10, 2 bsl 31 - 1}].
+    [{1, 10}, {0, 2 bsl 31 - 1}, {2 bsl 31 - 10, 2 bsl 31 - 1}].
 
 
 g_connected_intervals(Begin, End) ->
@@ -78,6 +91,20 @@ g_disconnected_intervals(Begin, End, Split) when Begin =< End ->
     end).
 
 
+g_random_intervals(Start, End) ->
+    ?LET(N, choose(1, 10),
+    begin
+        [begin
+            B = rand_range(Start, End),
+            E = rand_range(B, End),
+            {B, E}
+        end || _ <- lists:seq(1, N)]
+    end).
+
+
+rand_range(B, B) ->
+    B;
+
 rand_range(B, E) ->
     B + triq_rnd:uniform(E - B).
 
@@ -85,3 +112,8 @@ rand_range(B, E) ->
 shuffle(L) ->
     Tagged = [{triq_rnd:uniform(), X} || X <- L],
     [X || {_, X} <- lists:sort(Tagged)].
+
+
+endpoints(Ranges) ->
+    {Begins, Ends} = lists:unzip(Ranges),
+    sets:from_list(Begins ++ Ends).