Skip to content

Commit a47f786

Browse files
authored
Reverts leniency towards notfound limit-configs for v1 (#44)
* Revert "Makes get_batch/get_values lenient to nonexistent limit-configs too (#42)" This reverts commit 36eb612. * Partially reverts "Supresses `rollback_batch` exception for notfound limit-configs (#41)"
1 parent 36eb612 commit a47f786

3 files changed

Lines changed: 10 additions & 89 deletions

File tree

apps/limiter/src/lim_config_machine.erl

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ rollback(#limiter_LimitChange{id = ID, version = Version} = LimitChange, LimitCo
305305
{ok, [lim_liminator:limit_response()]} | {error, config_error() | {processor(), get_limit_error()}}.
306306
get_values(LimitChanges, LimitContext) ->
307307
do(fun() ->
308-
Changes = unwrap(collect_changes(hold, LimitChanges, LimitContext, lenient)),
308+
Changes = unwrap(collect_changes(hold, LimitChanges, LimitContext)),
309309
Names = lists:map(fun lim_liminator:get_name/1, Changes),
310310
unwrap(lim_liminator:get_values(Names, LimitContext))
311311
end).
@@ -316,11 +316,7 @@ get_batch(OperationID, LimitChanges, LimitContext) ->
316316
do(fun() ->
317317
unwrap(
318318
OperationID,
319-
lim_liminator:get(
320-
OperationID,
321-
unwrap(collect_changes(hold, LimitChanges, LimitContext, lenient)),
322-
LimitContext
323-
)
319+
lim_liminator:get(OperationID, unwrap(collect_changes(hold, LimitChanges, LimitContext)), LimitContext)
324320
)
325321
end).
326322

@@ -330,11 +326,7 @@ hold_batch(OperationID, LimitChanges, LimitContext) ->
330326
do(fun() ->
331327
unwrap(
332328
OperationID,
333-
lim_liminator:hold(
334-
OperationID,
335-
unwrap(collect_changes(hold, LimitChanges, LimitContext, strict)),
336-
LimitContext
337-
)
329+
lim_liminator:hold(OperationID, unwrap(collect_changes(hold, LimitChanges, LimitContext)), LimitContext)
338330
)
339331
end).
340332

@@ -344,11 +336,7 @@ commit_batch(OperationID, LimitChanges, LimitContext) ->
344336
do(fun() ->
345337
unwrap(
346338
OperationID,
347-
lim_liminator:commit(
348-
OperationID,
349-
unwrap(collect_changes(commit, LimitChanges, LimitContext, strict)),
350-
LimitContext
351-
)
339+
lim_liminator:commit(OperationID, unwrap(collect_changes(commit, LimitChanges, LimitContext)), LimitContext)
352340
)
353341
end).
354342

@@ -358,28 +346,17 @@ rollback_batch(OperationID, LimitChanges, LimitContext) ->
358346
do(fun() ->
359347
unwrap(
360348
OperationID,
361-
lim_liminator:rollback(
362-
OperationID,
363-
unwrap(collect_changes(hold, LimitChanges, LimitContext, lenient)),
364-
LimitContext
365-
)
349+
lim_liminator:rollback(OperationID, unwrap(collect_changes(hold, LimitChanges, LimitContext)), LimitContext)
366350
)
367351
end).
368352

369-
collect_changes(_Stage, [], _LimitContext, _Mode) ->
353+
collect_changes(_Stage, [], _LimitContext) ->
370354
{ok, []};
371-
collect_changes(Stage, [LimitChange = #limiter_LimitChange{id = ID, version = Version} | Other], LimitContext, Mode) ->
355+
collect_changes(Stage, [LimitChange = #limiter_LimitChange{id = ID, version = Version} | Other], LimitContext) ->
372356
do(fun() ->
373-
case {Mode, get_handler(ID, Version, LimitContext)} of
374-
{lenient, {error, {config, notfound}}} ->
375-
%% TODO Log that this limit-change was ignored because the
376-
%% mentioned limit-config was not found.
377-
unwrap(collect_changes(Stage, Other, LimitContext, Mode));
378-
{_, Result} ->
379-
{Handler, Config} = unwrap(Result),
380-
Change = unwrap(Handler, Handler:make_change(Stage, LimitChange, Config, LimitContext)),
381-
[Change | unwrap(collect_changes(Stage, Other, LimitContext, Mode))]
382-
end
357+
{Handler, Config} = unwrap(get_handler(ID, Version, LimitContext)),
358+
Change = unwrap(Handler, Handler:make_change(Stage, LimitChange, Config, LimitContext)),
359+
[Change | unwrap(collect_changes(Stage, Other, LimitContext))]
383360
end).
384361

385362
get_handler(ID, Version, LimitContext) ->

apps/limiter/src/lim_liminator.erl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@ get_name(#liminator_LimitChange{limit_name = Name}) ->
4343

4444
-spec get_values([limit_name()], lim_context()) ->
4545
{ok, [limit_response()]} | {error, invalid_request_error()}.
46-
get_values([], _LimitContext) ->
47-
{ok, []};
4846
get_values(Names, LimitContext) ->
4947
do('GetLastLimitsValues', Names, LimitContext).
5048

5149
-spec get(operation_id(), [limit_change()], lim_context()) ->
5250
{ok, [limit_response()]} | {error, invalid_request_error()}.
53-
get(_OperationID, [], _LimitContext) ->
54-
{ok, []};
5551
get(OperationID, Changes, LimitContext) ->
5652
do('Get', #liminator_LimitRequest{operation_id = OperationID, limit_changes = Changes}, LimitContext).
5753

@@ -65,8 +61,6 @@ commit(OperationID, Changes, LimitContext) ->
6561
do('Commit', #liminator_LimitRequest{operation_id = OperationID, limit_changes = Changes}, LimitContext).
6662

6763
-spec rollback(operation_id(), [limit_change()], lim_context()) -> {ok, ok} | {error, invalid_request_error()}.
68-
rollback(_OperationID, [], _LimitContext) ->
69-
{ok, ok};
7064
rollback(OperationID, Changes, LimitContext) ->
7165
do('Rollback', #liminator_LimitRequest{operation_id = OperationID, limit_changes = Changes}, LimitContext).
7266

apps/limiter/test/lim_turnover_SUITE.erl

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@
6969
-export([batch_hold_ok/1]).
7070
-export([batch_commit_ok/1]).
7171
-export([batch_rollback_ok/1]).
72-
-export([batch_rollback_lenient_to_config_notfound_ok/1]).
73-
-export([batch_get_values_lenient_to_config_notfound_ok/1]).
74-
-export([batch_hold_strict_to_config_notfound_ok/1]).
7572
-export([two_batch_hold_ok/1]).
7673
-export([two_batch_commit_ok/1]).
7774
-export([two_batch_rollback_ok/1]).
@@ -141,9 +138,6 @@ groups() ->
141138
batch_hold_ok,
142139
batch_commit_ok,
143140
batch_rollback_ok,
144-
batch_rollback_lenient_to_config_notfound_ok,
145-
batch_get_values_lenient_to_config_notfound_ok,
146-
batch_hold_strict_to_config_notfound_ok,
147141
two_batch_hold_ok,
148142
two_batch_commit_ok,
149143
two_batch_rollback_ok,
@@ -883,10 +877,6 @@ construct_request(C) ->
883877
?LIMIT_CHANGE(ID2, 0, Version2)
884878
]).
885879

886-
add_non_existent_limit_config(?LIMIT_REQUEST(_ID, Changes) = Request) ->
887-
NonexistentChange = ?LIMIT_CHANGE(<<"this-does-not-exist">>, 0, dmt_client:get_last_version()),
888-
Request#limiter_LimitRequest{limit_changes = [NonexistentChange | Changes]}.
889-
890880
-spec batch_hold_ok(config()) -> _.
891881
batch_hold_ok(C) ->
892882
Context =
@@ -921,46 +911,6 @@ batch_rollback_ok(C) ->
921911
{ok, ok} = lim_client:rollback_batch(Request, Context, ?config(client, C)),
922912
ok = assert_values(0, Request, Context, C).
923913

924-
-spec batch_rollback_lenient_to_config_notfound_ok(config()) -> _.
925-
batch_rollback_lenient_to_config_notfound_ok(C) ->
926-
Context =
927-
case get_group_name(C) of
928-
withdrawals -> ?wthdproc_ctx_withdrawal(?cash(10));
929-
_Default -> ?payproc_ctx_payment(?cash(10), ?cash(10))
930-
end,
931-
Request0 = construct_request(C),
932-
ok = hold_and_assert_batch(10, Request0, Context, C),
933-
Request1 = add_non_existent_limit_config(Request0),
934-
{ok, ok} = lim_client:rollback_batch(Request1, Context, ?config(client, C)),
935-
ok = assert_values(0, Request0, Context, C).
936-
937-
-spec batch_get_values_lenient_to_config_notfound_ok(config()) -> _.
938-
batch_get_values_lenient_to_config_notfound_ok(C) ->
939-
Context =
940-
case get_group_name(C) of
941-
withdrawals -> ?wthdproc_ctx_withdrawal(?cash(10));
942-
_Default -> ?payproc_ctx_payment(?cash(10), ?cash(10))
943-
end,
944-
Request0 = construct_request(C),
945-
ok = hold_and_assert_batch(10, Request0, Context, C),
946-
Request1 = add_non_existent_limit_config(Request0),
947-
ok = assert_batch(10, Request1, Context, C),
948-
ok = assert_values(10, Request1, Context, C).
949-
950-
-spec batch_hold_strict_to_config_notfound_ok(config()) -> _.
951-
batch_hold_strict_to_config_notfound_ok(C) ->
952-
Context =
953-
case get_group_name(C) of
954-
withdrawals -> ?wthdproc_ctx_withdrawal(?cash(10));
955-
_Default -> ?payproc_ctx_payment(?cash(10), ?cash(10))
956-
end,
957-
Request0 = construct_request(C),
958-
Request1 = add_non_existent_limit_config(Request0),
959-
?assertEqual(
960-
{exception, #limiter_LimitNotFound{}},
961-
lim_client:hold_batch(Request1, Context, ?config(client, C))
962-
).
963-
964914
-spec two_batch_hold_ok(config()) -> _.
965915
two_batch_hold_ok(C) ->
966916
Context =

0 commit comments

Comments
 (0)