From 19d8f57198f2cbe5b64aa4a923ba32774e505503 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Tue, 14 May 2024 13:44:13 +0300 Subject: [PATCH] FIN-31: Adds support for snapshot creation timestamp (#7) * FIN-31: Adds support for snapshot creation timestamp * Bumps CI workflow * Temporarily disables codecov report upload; fixes protocol and dialyzer warnings * Fix possible bug for partial history backwards traversal --- .github/workflows/erlang-checks.yml | 3 ++- rebar.config | 2 +- rebar.lock | 2 +- src/dmt_history.erl | 18 ++++++++++++++---- test/bench_apply_operations.erl | 2 +- test/dmt_domain_tests.erl | 15 +++++++++++++-- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/erlang-checks.yml b/.github/workflows/erlang-checks.yml index d4fa15c..5a9f086 100644 --- a/.github/workflows/erlang-checks.yml +++ b/.github/workflows/erlang-checks.yml @@ -30,9 +30,10 @@ jobs: run: name: Run checks needs: setup - uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.1 + uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.14 with: otp-version: ${{ needs.setup.outputs.otp-version }} rebar-version: ${{ needs.setup.outputs.rebar-version }} use-thrift: true thrift-version: ${{ needs.setup.outputs.thrift-version }} + upload-coverage: false diff --git a/rebar.config b/rebar.config index 9e87ba1..37d8a43 100644 --- a/rebar.config +++ b/rebar.config @@ -45,7 +45,7 @@ % mandatory unmatched_returns, error_handling, - race_conditions, + % NOTE 'race_conditions' was removed https://www.erlang.org/doc/apps/dialyzer/notes#dialyzer-5.0 unknown ]}, {plt_apps, all_deps} diff --git a/rebar.lock b/rebar.lock index f8f0bd4..b1cd0b4 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,6 +1,6 @@ [{<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"dac2cb599499cc0701e60856f4092c9ab283eedf"}}, + {ref,"ab292d91f5265237351342675c8f69de17add673"}}, 0}, {<<"genlib">>, {git,"https://github.com/rbkmoney/genlib.git", diff --git a/src/dmt_history.erl b/src/dmt_history.erl index 2707484..f204c2e 100644 --- a/src/dmt_history.erl +++ b/src/dmt_history.erl @@ -12,7 +12,7 @@ -spec head(history()) -> {ok, snapshot()} | {error, dmt_domain:operation_error()}. head(History) -> - head(History, #domain_conf_Snapshot{version = 0, domain = dmt_domain:new()}). + head(History, #domain_conf_Snapshot{version = 0, domain = dmt_domain:new(), created_at = undefined}). -spec head(history(), snapshot()) -> {ok, snapshot()} | {error, dmt_domain:operation_error()}. head(History, Snapshot) when map_size(History) =:= 0 -> @@ -25,12 +25,13 @@ head(History, Snapshot) -> travel(To, _History, #domain_conf_Snapshot{version = From} = Snapshot) when To =:= From -> {ok, Snapshot}; travel(To, History, #domain_conf_Snapshot{version = From, domain = Domain}) when To > From -> - #domain_conf_Commit{ops = Ops} = maps:get(From + 1, History), + #domain_conf_Commit{ops = Ops, created_at = CreatedAt} = maps:get(From + 1, History), case dmt_domain:apply_operations(Ops, Domain) of {ok, NewDomain} -> NextSnapshot = #domain_conf_Snapshot{ version = From + 1, - domain = NewDomain + domain = NewDomain, + created_at = CreatedAt }, travel(To, History, NextSnapshot); {error, _} = Error -> @@ -38,11 +39,20 @@ travel(To, History, #domain_conf_Snapshot{version = From, domain = Domain}) when end; travel(To, History, #domain_conf_Snapshot{version = From, domain = Domain}) when To < From -> #domain_conf_Commit{ops = Ops} = maps:get(From, History), + %% NOTE In case of backwards traversal of partial history of + %% commits there may be no 'previous' commit. Use 'undefined' + %% for creation timestamp as a fallback value. + CreatedAt = + case maps:get(From - 1, History, undefined) of + #domain_conf_Commit{created_at = T} -> T; + undefined -> undefined + end, case dmt_domain:revert_operations(Ops, Domain) of {ok, NewDomain} -> PreviousSnapshot = #domain_conf_Snapshot{ version = From - 1, - domain = NewDomain + domain = NewDomain, + created_at = CreatedAt }, travel(To, History, PreviousSnapshot); {error, _} = Error -> diff --git a/test/bench_apply_operations.erl b/test/bench_apply_operations.erl index 3760fa2..72283a6 100644 --- a/test/bench_apply_operations.erl +++ b/test/bench_apply_operations.erl @@ -12,7 +12,7 @@ -type commit() :: dmsl_domain_conf_thrift:'Commit'(). -record(st, { - snapshot = #domain_conf_Snapshot{version = 0, domain = dmt_domain:new()} :: snapshot(), + snapshot = #domain_conf_Snapshot{version = 0, domain = dmt_domain:new(), created_at = undefined} :: snapshot(), history = #{} :: #{_Version => commit()} }). diff --git a/test/dmt_domain_tests.erl b/test/dmt_domain_tests.erl index 16023cb..9482920 100644 --- a/test/dmt_domain_tests.erl +++ b/test/dmt_domain_tests.erl @@ -194,7 +194,14 @@ wrong_spec_order_test() -> terms = #domain_ProvisionTermSet{ payments = #domain_PaymentsProvisionTerms{ categories = {value, [?category_ref(1)]}, - payment_methods = {value, [#domain_PaymentMethodRef{id = {bank_card, visa}}]}, + payment_methods = + {value, [ + ?payment_method_ref( + {bank_card, #domain_BankCardPaymentMethod{ + payment_system = #domain_PaymentSystemRef{id = <<"visa-ref">>} + }} + ) + ]}, cash_flow = {value, []} } } @@ -214,7 +221,11 @@ wrong_spec_order_test() -> PaymentMethod = { payment_method, #domain_PaymentMethodObject{ - ref = ?payment_method_ref({bank_card, visa}), + ref = ?payment_method_ref( + {bank_card, #domain_BankCardPaymentMethod{ + payment_system = #domain_PaymentSystemRef{id = <<"visa-ref">>} + }} + ), data = #domain_PaymentMethodDefinition{ name = <<"VISA">>, description = <<"VISA BANK CARD">>