From e2c0646fbad9f851a0abc9c74eb7b07b00983a6f Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Mon, 30 May 2022 13:08:46 +0300 Subject: [PATCH 1/3] antidote-crdt: add tests for multi ops on same key (map types) --- apps/antidote_crdt/src/antidote_crdt_map_go.erl | 10 +++++++++- apps/antidote_crdt/src/antidote_crdt_map_rr.erl | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/antidote_crdt/src/antidote_crdt_map_go.erl b/apps/antidote_crdt/src/antidote_crdt_map_go.erl index bec421df..a02a02de 100644 --- a/apps/antidote_crdt/src/antidote_crdt_map_go.erl +++ b/apps/antidote_crdt/src/antidote_crdt_map_go.erl @@ -176,6 +176,14 @@ update2_test() -> Map1 = new(), {ok, Effect1} = downstream({update, [{{a, antidote_crdt_set_aw}, {add, a}}]}, Map1), {ok, Map2} = update(Effect1, Map1), - ?assertEqual([{{a, antidote_crdt_set_aw}, [a]}], value(Map2)). + ?assertEqual([{{a, antidote_crdt_set_aw}, [a]}], value(Map2)), + Op = {update, [ + {{a, antidote_crdt_set_aw}, {remove, a}}, + {{a, antidote_crdt_set_aw}, {add, b}} + ]}, + ?assert(is_operation(Op)), + {ok, Effect2} = downstream(Op, Map2), + {ok, Map3} = update(Effect2, Map2), + ?assertEqual([{{a, antidote_crdt_set_aw}, [b]}], value(Map3)). -endif. diff --git a/apps/antidote_crdt/src/antidote_crdt_map_rr.erl b/apps/antidote_crdt/src/antidote_crdt_map_rr.erl index c27622bb..344cddef 100644 --- a/apps/antidote_crdt/src/antidote_crdt_map_rr.erl +++ b/apps/antidote_crdt/src/antidote_crdt_map_rr.erl @@ -384,6 +384,17 @@ upd(Update, State) -> {ok, Res} = update(Downstream, State), Res. +multiple_ops_on_same_key_test() -> + M1 = new(), + M2 = upd({update, {{a, antidote_crdt_set_rw}, {add, <<"a">>}}}, M1), + Op = {update, [ + {{a, antidote_crdt_set_rw}, {remove, <<"a">>}}, + {{a, antidote_crdt_set_rw}, {add, <<"b">>}} + ]}, + ?assert(is_operation(Op)), + M3 = upd(Op, M2), + ?assertEqual([{{a, antidote_crdt_set_rw}, [<<"b">>]}], value(M3)). + remove_test() -> M1 = new(), ?assertEqual([], value(M1)), From 29bb039d7ce32ffe07ff322197cb30e3048f763c Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Mon, 30 May 2022 15:28:46 +0300 Subject: [PATCH 2/3] Broken proptests --- apps/antidote_crdt/test/prop_map_go.erl | 9 +-------- apps/antidote_crdt/test/prop_map_rr.erl | 20 +++----------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/apps/antidote_crdt/test/prop_map_go.erl b/apps/antidote_crdt/test/prop_map_go.erl index ba43da47..07fdc213 100644 --- a/apps/antidote_crdt/test/prop_map_go.erl +++ b/apps/antidote_crdt/test/prop_map_go.erl @@ -64,16 +64,9 @@ op() -> ?SIZED(Size, op(Size)). op(Size) -> {update, oneof([ nestedOp(Size), - ?LET(L, list(nestedOp(Size div 2)), removeDuplicateKeys(L, [])) + ?LET(L, list(nestedOp(Size div 2)), L) ])}. -removeDuplicateKeys([], _) -> []; -removeDuplicateKeys([{Key, Op}|Rest], Keys) -> - case lists:member(Key, Keys) of - true -> removeDuplicateKeys(Rest, Keys); - false -> [{Key, Op}|removeDuplicateKeys(Rest, [Key|Keys])] - end. - nestedOp(Size) -> oneof( [ diff --git a/apps/antidote_crdt/test/prop_map_rr.erl b/apps/antidote_crdt/test/prop_map_rr.erl index fabc03d6..2f1b82ac 100644 --- a/apps/antidote_crdt/test/prop_map_rr.erl +++ b/apps/antidote_crdt/test/prop_map_rr.erl @@ -99,26 +99,17 @@ op() -> ?SIZED(Size, op(Size)). op(Size) -> oneof([ {update, nestedOp(Size)}, - {update, ?LET(L, list(nestedOp(Size div 2)), removeDuplicateKeys(L, []))}, + {update, ?LET(L, list(nestedOp(Size div 2)), L)}, {remove, typed_key()}, - {remove, ?LET(L, list(typed_key()), lists:usort(L))}, + {remove, ?LET(L, list(typed_key()), L)}, ?LET({Updates, Removes}, {list(nestedOp(Size div 2)), list(typed_key())}, begin - Removes2 = lists:usort(Removes), - Updates2 = removeDuplicateKeys(Updates, Removes2), - {batch, {Updates2, Removes2}} + {batch, {Updates, Removes}} end), {reset, {}} ]). -removeDuplicateKeys([], _) -> []; -removeDuplicateKeys([{Key, Op}|Rest], Keys) -> - case lists:member(Key, Keys) of - true -> removeDuplicateKeys(Rest, Keys); - false -> [{Key, Op}|removeDuplicateKeys(Rest, [Key|Keys])] - end. - nestedOp(Size) -> oneof( [ @@ -141,8 +132,3 @@ crdt_type() -> key() -> oneof([key1, key2, key3, key4]). - - - - - From b63e446dd32304ea0cf38c466b4d1f3ee3b7b704 Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Wed, 1 Jun 2022 09:59:22 +0300 Subject: [PATCH 3/3] failing test --- apps/antidote_crdt/src/antidote_crdt_map_go.erl | 8 +++++--- apps/antidote_crdt/src/antidote_crdt_map_rr.erl | 13 ++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/antidote_crdt/src/antidote_crdt_map_go.erl b/apps/antidote_crdt/src/antidote_crdt_map_go.erl index a02a02de..bdc8600a 100644 --- a/apps/antidote_crdt/src/antidote_crdt_map_go.erl +++ b/apps/antidote_crdt/src/antidote_crdt_map_go.erl @@ -178,12 +178,14 @@ update2_test() -> {ok, Map2} = update(Effect1, Map1), ?assertEqual([{{a, antidote_crdt_set_aw}, [a]}], value(Map2)), Op = {update, [ - {{a, antidote_crdt_set_aw}, {remove, a}}, - {{a, antidote_crdt_set_aw}, {add, b}} + {{a, antidote_crdt_set_aw}, {add, a}}, + {{a, antidote_crdt_set_aw}, {add, b}}, + {{a, antidote_crdt_set_aw}, {add, c}}, + {{a, antidote_crdt_set_aw}, {remove, a}} ]}, ?assert(is_operation(Op)), {ok, Effect2} = downstream(Op, Map2), {ok, Map3} = update(Effect2, Map2), - ?assertEqual([{{a, antidote_crdt_set_aw}, [b]}], value(Map3)). + ?assertEqual([{{a, antidote_crdt_set_aw}, [ b, c]}], value(Map3)). -endif. diff --git a/apps/antidote_crdt/src/antidote_crdt_map_rr.erl b/apps/antidote_crdt/src/antidote_crdt_map_rr.erl index 344cddef..4b959774 100644 --- a/apps/antidote_crdt/src/antidote_crdt_map_rr.erl +++ b/apps/antidote_crdt/src/antidote_crdt_map_rr.erl @@ -141,6 +141,7 @@ generate_downstream_update({{Key, Type}, Op}, CurrentMap) -> false -> antidote_crdt:new(Type) end, {ok, DownstreamEffect} = antidote_crdt:downstream(Type, Op, CurrentState), + io:format("effect: ~p~n", [DownstreamEffect]), {{Key, Type}, {ok, DownstreamEffect}}. -spec generate_downstream_remove(typedKey(), state()) -> nested_downstream(). @@ -386,14 +387,16 @@ upd(Update, State) -> multiple_ops_on_same_key_test() -> M1 = new(), - M2 = upd({update, {{a, antidote_crdt_set_rw}, {add, <<"a">>}}}, M1), Op = {update, [ - {{a, antidote_crdt_set_rw}, {remove, <<"a">>}}, - {{a, antidote_crdt_set_rw}, {add, <<"b">>}} + {{a, antidote_crdt_set_rw}, {remove, <<"c">>}}, + {{a, antidote_crdt_set_rw}, {add, <<"c">>}} ]}, ?assert(is_operation(Op)), - M3 = upd(Op, M2), - ?assertEqual([{{a, antidote_crdt_set_rw}, [<<"b">>]}], value(M3)). + M2 = upd(Op, M1), + Op2 = {update, {{a, antidote_crdt_set_rw}, {remove, <<"c">>}}}, + Op3 = {update, {{a, antidote_crdt_set_rw}, {add, <<"c">>}}}, + M3 = upd(Op3, upd(Op2, M1)), + ?assertEqual(value(M3), value(M2)). remove_test() -> M1 = new(),