Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/tag-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Create Tag

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- uses: valitydev/action-tagger@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
with-v: true
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEV_IMAGE_TAG = $(TEST_CONTAINER_NAME)-dev
DEV_IMAGE_ID = $(file < .image.dev)

DOCKER ?= docker
DOCKERCOMPOSE ?= docker-compose
DOCKERCOMPOSE ?= docker compose
DOCKERCOMPOSE_W_ENV = DEV_IMAGE_TAG=$(DEV_IMAGE_TAG) $(DOCKERCOMPOSE) -f compose.yaml -f compose.tracing.yaml
REBAR ?= rebar3
TEST_CONTAINER_NAME ?= testrunner
Expand Down Expand Up @@ -64,6 +64,16 @@ wdeps-%: dev-image
$(DOCKERCOMPOSE_W_ENV) down; \
exit $$res

# Database tasks

ifeq (db,$(firstword $(MAKECMDGOALS)))
DATABASE_NAME := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(DATABASE_NAME):;@:)
endif

db:
$(DOCKERCOMPOSE_W_ENV) exec db bash -c "PGPASSWORD=postgres psql -U $(DATABASE_NAME) -d $(DATABASE_NAME)"

# Rebar tasks

rebar-shell:
Expand Down
86 changes: 35 additions & 51 deletions apps/hellgate/src/hg_domain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,23 @@

-module(hg_domain).

-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_conf_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl").

%%

-export([head/0]).
-export([get/1]).
-export([get/2]).
-export([get_without_exp/2]).
-export([find/2]).
-export([exists/2]).
-export([commit/2]).
-export([reset/1]).

-export([insert/1]).
-export([update/1]).
-export([upsert/1]).
-export([remove/1]).
-export([cleanup/0]).

%%

-type revision() :: dmt_client:version().
-type revision() :: dmt_client:vsn().
-type ref() :: dmsl_domain_thrift:'Reference'().
-type object() :: dmsl_domain_thrift:'DomainObject'().
-type data() :: _.
Expand All @@ -42,7 +36,7 @@

-spec head() -> revision().
head() ->
dmt_client:get_last_version().
dmt_client:get_latest_version().

-spec get(ref()) -> data() | no_return().
get(Ref) ->
Expand All @@ -53,69 +47,59 @@ get(Revision, Ref) ->
try
extract_data(dmt_client:checkout_object(Revision, Ref))
catch
throw:#domain_conf_ObjectNotFound{} ->
throw:#domain_conf_v2_ObjectNotFound{} ->
error({object_not_found, {Revision, Ref}})
end.

-spec get_without_exp(dmt_client:version(), ref()) -> data() | get_error().
get_without_exp(Revision, Ref) ->
try
extract_data(dmt_client:checkout_object(Revision, Ref))
catch
throw:#domain_conf_ObjectNotFound{} ->
{object_not_found, {Revision, Ref}}
end.

-spec find(revision(), ref()) -> data() | notfound.
find(Revision, Ref) ->
try
extract_data(dmt_client:checkout_object(Revision, Ref))
catch
throw:#domain_conf_ObjectNotFound{} ->
notfound
end.

-spec exists(revision(), ref()) -> boolean().
exists(Revision, Ref) ->
try
_ = dmt_client:checkout_object(Revision, Ref),
true
catch
throw:#domain_conf_ObjectNotFound{} ->
false
end.

extract_data({_Tag, {_Name, _Ref, Data}}) ->
extract_data(#domain_conf_v2_VersionedObject{object = {_Tag, {_Name, _Ref, Data}}}) ->
Data.

-spec commit(revision(), dmt_client:commit()) -> revision() | no_return().
commit(Revision, Commit) ->
dmt_client:commit(Revision, Commit).

-spec reset(revision()) -> revision() | no_return().
reset(ToRevision) ->
#domain_conf_Snapshot{domain = Domain} = dmt_client:checkout(ToRevision),
upsert(maps:values(Domain)).
Objects = dmt_client:checkout_all(ToRevision),
upsert(unwrap_versioned_objects(Objects)).

%% convenience shortcuts, use carefully

-spec insert(object() | [object()]) -> revision() | no_return().
insert(ObjectOrMany) ->
dmt_client:insert(ObjectOrMany).
dmt_client:insert(ObjectOrMany, ensure_stub_author()).

-spec update(object() | [object()]) -> revision() | no_return().
update(NewObjectOrMany) ->
dmt_client:update(NewObjectOrMany).
dmt_client:update(NewObjectOrMany, ensure_stub_author()).

-spec upsert(object() | [object()]) -> revision() | no_return().
upsert(NewObjectOrMany) ->
dmt_client:upsert(NewObjectOrMany).
%% NOTE Checkout all objects from target version to ensure it all
%% cached before operations preparation.
Version = dmt_client:get_latest_version(),
_ = dmt_client:checkout_all(Version),
dmt_client:upsert(Version, NewObjectOrMany, ensure_stub_author()).

-spec remove(object() | [object()]) -> revision() | no_return().
remove(ObjectOrMany) ->
dmt_client:remove(ObjectOrMany).
dmt_client:remove(ObjectOrMany, ensure_stub_author()).

-spec cleanup() -> revision() | no_return().
cleanup() ->
#domain_conf_Snapshot{domain = Domain} = dmt_client:checkout(latest),
remove(maps:values(Domain)).
Objects = dmt_client:checkout_all(latest),
remove(unwrap_versioned_objects(Objects)).

ensure_stub_author() ->
%% TODO DISCUSS Stubs and fallback authors
ensure_author(~b"unknown", ~b"unknown@local").

ensure_author(Name, Email) ->
try
#domain_conf_v2_Author{id = ID} = dmt_client:get_author_by_email(Email),
ID
catch
throw:#domain_conf_v2_AuthorNotFound{} ->
dmt_client:create_author(Name, Email)
end.

%%

unwrap_versioned_objects(VersionedObjects) ->
lists:map(fun(#domain_conf_v2_VersionedObject{object = Object}) -> Object end, VersionedObjects).
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_invoice_payment_refund.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
-type session() :: hg_session:t().
-type trx_info() :: dmsl_domain_thrift:'TransactionInfo'().
-type failure() :: dmsl_domain_thrift:'OperationFailure'().
-type revision() :: dmt_client:version().
-type revision() :: dmt_client:vsn().
-type cash() :: dmsl_domain_thrift:'Cash'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type route() :: dmsl_domain_thrift:'PaymentRoute'().
Expand Down
13 changes: 7 additions & 6 deletions apps/hellgate/test/hg_ct_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ start_app(dmt_client = AppName) ->
}}
]},
{service_urls, #{
'Repository' => <<"http://dominant:8022/v1/domain/repository">>,
'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">>
'AuthorManagement' => <<"http://dmt:8022/v1/domain/author">>,
'Repository' => <<"http://dmt:8022/v1/domain/repository">>,
'RepositoryClient' => <<"http://dmt:8022/v1/domain/repository_client">>
}}
]),
#{}
Expand Down Expand Up @@ -268,11 +269,11 @@ start_app(epg_connector = AppName) ->
start_app(AppName, [
{databases, #{
default_db => #{
host => "postgres",
host => "db",
port => 5432,
database => "progressor_db",
username => "progressor",
password => "progressor"
database => "hellgate",
username => "hellgate",
password => "postgres"
}
}},
{pools, #{
Expand Down
32 changes: 21 additions & 11 deletions apps/hellgate/test/hg_invoice_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ end).

-spec init_per_group(group_name(), config()) -> config().
init_per_group(route_cascading, C) ->
init_route_cascading_group(C);
[{pre_group_domain_revision, hg_domain:head()} | init_route_cascading_group(C)];
init_per_group(operation_limits, C) ->
init_operation_limits_group(C);
init_per_group(repair_preproc_w_limits, C) ->
Expand All @@ -650,8 +650,14 @@ init_per_group(_, C) ->
C.

-spec end_per_group(group_name(), config()) -> _.
end_per_group(_Group, _C) ->
ok.
end_per_group(_Group, C) ->
case cfg(pre_group_domain_revision, C) of
Revision when is_integer(Revision) ->
_ = hg_domain:reset(Revision),
ok;
undefined ->
ok
end.

-spec init_per_testcase(test_case_name(), config()) -> config().
init_per_testcase(Name, C) when
Expand Down Expand Up @@ -1185,7 +1191,7 @@ payment_shop_limit_success(C) ->
#domain_TurnoverLimit{
id = ?SHOPLIMIT_ID,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
],
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
Expand All @@ -1206,7 +1212,7 @@ payment_shop_limit_overflow(C) ->
#domain_TurnoverLimit{
id = ?SHOPLIMIT_ID,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
]),
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
Expand All @@ -1229,7 +1235,7 @@ payment_shop_limit_more_overflow(C) ->
#domain_TurnoverLimit{
id = ?SHOPLIMIT_ID,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
]),
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
Expand Down Expand Up @@ -6009,7 +6015,9 @@ cascade_fixture(Revision, C) ->
init_route_cascading_group(C1) ->
PartyID = cfg(party_id, C1),
PartyClient = cfg(party_client, C1),
_ = override_domain_fixture(fun cascade_fixture_pre_shop_create/2, undefined, C1),
Revision = hg_domain:head(),
ok = hg_context:save(hg_context:create()),
_ = hg_domain:upsert(cascade_fixture_pre_shop_create(Revision, C1)),
C2 = [
{
{shop_id, ?PAYMENT_CASCADE_SUCCESS_ID},
Expand Down Expand Up @@ -6095,7 +6103,9 @@ init_route_cascading_group(C1) ->
}
| C1
],
override_domain_fixture(fun cascade_fixture/2, undefined, C2).
ok = hg_context:cleanup(),
_ = hg_domain:upsert(cascade_fixture(Revision, C2)),
[{base_limits_domain_revision, Revision} | C2].

init_per_cascade_case(payment_cascade_success, C) ->
ShopID = cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_ID}, C),
Expand Down Expand Up @@ -9361,7 +9371,7 @@ construct_domain_fixture() ->
#domain_TurnoverLimit{
id = ?LIMIT_ID,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
]}
}
Expand Down Expand Up @@ -9414,7 +9424,7 @@ construct_domain_fixture() ->
#domain_TurnoverLimit{
id = ?LIMIT_ID2,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
]}
}
Expand Down Expand Up @@ -9459,7 +9469,7 @@ construct_domain_fixture() ->
#domain_TurnoverLimit{
id = ?LIMIT_ID3,
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
domain_revision = dmt_client:get_last_version()
domain_revision = hg_domain:head()
}
]}
}
Expand Down
19 changes: 12 additions & 7 deletions apps/hellgate/test/hg_limiter_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@

-spec init_per_suite(config()) -> dmt_client:vsn().
init_per_suite(_Config) ->
dmt_client:upsert([
{limit_config, mk_config_object(?LIMIT_ID)},
{limit_config, mk_config_object(?LIMIT_ID2)},
{limit_config, mk_config_object(?LIMIT_ID3)},
{limit_config, mk_config_object(?LIMIT_ID4)},
{limit_config, mk_config_object(?SHOPLIMIT_ID)}
]).
dmt_client:upsert(
latest,
[
{limit_config, mk_config_object(?LIMIT_ID)},
{limit_config, mk_config_object(?LIMIT_ID2)},
{limit_config, mk_config_object(?LIMIT_ID3)},
{limit_config, mk_config_object(?LIMIT_ID4)},
{limit_config, mk_config_object(?SHOPLIMIT_ID)}
],
dmt_client:create_author(genlib:unique(), genlib:unique()),
#{}
).

-spec get_amount(_) -> pos_integer().
get_amount(#limiter_Limit{amount = Amount}) ->
Expand Down
6 changes: 4 additions & 2 deletions apps/hellgate/test/hg_mock_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ mock_services(Services, SupPid) ->
mock_dominant(Services0, SupPid) ->
Services1 = lists:map(
fun
({'AuthorManagement', Fun}) ->
{'AuthorManagement', {dmsl_domain_conf_v2_thrift, 'AuthorManagement'}, Fun};
({'Repository', Fun}) ->
{'Repository', {dmsl_domain_conf_thrift, 'Repository'}, Fun};
{'Repository', {dmsl_domain_conf_v2_thrift, 'Repository'}, Fun};
({'RepositoryClient', Fun}) ->
{'RepositoryClient', {dmsl_domain_conf_thrift, 'RepositoryClient'}, Fun}
{'RepositoryClient', {dmsl_domain_conf_v2_thrift, 'RepositoryClient'}, Fun}
end,
Services0
),
Expand Down
Loading
Loading