Skip to content

Commit

Permalink
antidote-crdt: add tests for multi ops on same key (map types)
Browse files Browse the repository at this point in the history
  • Loading branch information
v0idpwn committed May 30, 2022
1 parent ae3dcce commit e2c0646
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/antidote_crdt/src/antidote_crdt_map_go.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
11 changes: 11 additions & 0 deletions apps/antidote_crdt/src/antidote_crdt_map_rr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit e2c0646

Please sign in to comment.