Skip to content

Commit bdf7778

Browse files
author
ttt161
committed
add tests for process tracing
1 parent 33a3a1d commit bdf7778

File tree

6 files changed

+198
-6
lines changed

6 files changed

+198
-6
lines changed

apps/ff_server/test/ff_deposit_handler_SUITE.erl

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
-export([unknown_test/1]).
3131
-export([get_context_test/1]).
3232
-export([get_events_test/1]).
33+
-export([trace_deposit_ok_test/1]).
3334

3435
%% Internal types
3536

@@ -56,7 +57,8 @@ groups() ->
5657
create_negative_ok_test,
5758
unknown_test,
5859
get_context_test,
59-
get_events_test
60+
get_events_test,
61+
trace_deposit_ok_test
6062
]}
6163
].
6264

@@ -221,6 +223,58 @@ create_ok_test(_C) ->
221223
ff_codec:unmarshal(timestamp_ms, DepositState#deposit_DepositState.created_at)
222224
).
223225

226+
-spec trace_deposit_ok_test(config()) -> test_return().
227+
trace_deposit_ok_test(_C) ->
228+
Body = make_cash({100, <<"RUB">>}),
229+
#{
230+
party_id := PartyID,
231+
wallet_id := WalletID,
232+
source_id := SourceID
233+
} = ct_objects:prepare_standard_environment(ct_objects:build_default_ctx()),
234+
DepositID = genlib:bsuuid(),
235+
ExternalID = genlib:bsuuid(),
236+
Context = #{<<"NS">> => #{genlib:bsuuid() => genlib:bsuuid()}},
237+
Metadata = ff_entity_context_codec:marshal(#{<<"metadata">> => #{<<"some key">> => <<"some data">>}}),
238+
Description = <<"testDesc">>,
239+
Params = #deposit_DepositParams{
240+
id = DepositID,
241+
party_id = PartyID,
242+
body = Body,
243+
source_id = SourceID,
244+
wallet_id = WalletID,
245+
metadata = Metadata,
246+
external_id = ExternalID,
247+
description = Description
248+
},
249+
{ok, _DepositState} = call_deposit('Create', {Params, ff_entity_context_codec:marshal(Context)}),
250+
timer:sleep(1000),
251+
TraceUrl = <<"http://localhost:8022/traces/internal/deposit_v1/", DepositID/binary>>,
252+
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
253+
{ok, TraceBody} = hackney:body(Ref),
254+
[
255+
#{
256+
<<"args">> := [
257+
[
258+
#{<<"created">> := _},
259+
#{<<"status_changed">> := <<"pending">>}
260+
],
261+
#{<<"NS">> := _}
262+
],
263+
<<"events">> := [
264+
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
265+
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"status_changed">> := _}, <<"event_timestamp">> := _}
266+
],
267+
<<"task_status">> := <<"finished">>,
268+
<<"task_type">> := <<"init">>
269+
},
270+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
271+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
272+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
273+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
274+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>}
275+
] = json:decode(TraceBody),
276+
ok.
277+
224278
-spec create_negative_ok_test(config()) -> test_return().
225279
create_negative_ok_test(_C) ->
226280
Body = make_cash({-100, <<"RUB">>}),

apps/ff_server/test/ff_destination_handler_SUITE.erl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-export([create_ripple_wallet_destination_ok/1]).
2020
-export([create_digital_wallet_destination_ok/1]).
2121
-export([create_generic_destination_ok/1]).
22+
-export([trace_destination_test/1]).
2223

2324
-type config() :: ct_helper:config().
2425
-type test_case_name() :: ct_helper:test_case_name().
@@ -37,7 +38,8 @@ groups() ->
3738
create_crypto_wallet_destination_ok,
3839
create_ripple_wallet_destination_ok,
3940
create_digital_wallet_destination_ok,
40-
create_generic_destination_ok
41+
create_generic_destination_ok,
42+
trace_destination_test
4143
]}
4244
].
4345

@@ -139,6 +141,42 @@ create_generic_destination_ok(C) ->
139141
}},
140142
create_destination_ok(Resource, C).
141143

144+
-spec trace_destination_test(config()) -> test_return().
145+
trace_destination_test(C) ->
146+
Resource =
147+
{bank_card, #'fistful_base_ResourceBankCard'{
148+
bank_card = #'fistful_base_BankCard'{
149+
token = <<"TOKEN shmOKEN">>
150+
}
151+
}},
152+
AuthData =
153+
{sender_receiver, #destination_SenderReceiverAuthData{
154+
sender = <<"SenderToken">>,
155+
receiver = <<"ReceiverToken">>
156+
}},
157+
{ok, #destination_DestinationState{id = ID}} = create_destination_ok(AuthData, Resource, C),
158+
TraceUrl = <<"http://localhost:8022/traces/internal/destination_v2/", ID/binary>>,
159+
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
160+
{ok, Body} = hackney:body(Ref),
161+
[
162+
#{
163+
<<"args">> := [
164+
[
165+
#{<<"created">> := _},
166+
#{<<"account">> := _}
167+
],
168+
#{<<"NS">> := #{}}
169+
],
170+
<<"events">> := [
171+
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
172+
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"account">> := _}, <<"event_timestamp">> := _}
173+
],
174+
<<"task_status">> := <<"finished">>,
175+
<<"task_type">> := <<"init">>
176+
}
177+
] = json:decode(Body),
178+
ok.
179+
142180
%%----------------------------------------------------------------------
143181
%% Internal functions
144182
%%----------------------------------------------------------------------

apps/ff_server/test/ff_source_handler_SUITE.erl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-export([get_source_context_ok_test/1]).
2020
-export([create_source_ok_test/1]).
2121
-export([unknown_test/1]).
22+
-export([trace_source_ok_test/1]).
2223

2324
-type config() :: ct_helper:config().
2425
-type test_case_name() :: ct_helper:test_case_name().
@@ -36,7 +37,8 @@ groups() ->
3637
get_source_events_ok_test,
3738
get_source_context_ok_test,
3839
create_source_ok_test,
39-
unknown_test
40+
unknown_test,
41+
trace_source_ok_test
4042
]}
4143
].
4244

@@ -104,6 +106,37 @@ create_source_ok_test(C) ->
104106
}},
105107
create_source_ok(Resource, C).
106108

109+
-spec trace_source_ok_test(config()) -> test_return().
110+
trace_source_ok_test(C) ->
111+
Resource =
112+
{internal, #source_Internal{
113+
details = <<"details">>
114+
}},
115+
State = create_source_ok(Resource, C),
116+
ID = State#source_SourceState.id,
117+
TraceUrl = <<"http://localhost:8022/traces/internal/source_v1/", ID/binary>>,
118+
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
119+
{ok, Body} = hackney:body(Ref),
120+
[
121+
#{
122+
<<"args">> := [
123+
[
124+
#{<<"created">> := _},
125+
#{<<"account">> := _}
126+
],
127+
#{<<"NS">> := #{}}
128+
],
129+
<<"events">> := [
130+
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
131+
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"account">> := _}, <<"event_timestamp">> := _}
132+
],
133+
<<"task_status">> := <<"finished">>,
134+
<<"task_type">> := <<"init">>
135+
},
136+
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>}
137+
] = json:decode(Body),
138+
ok.
139+
107140
-spec unknown_test(config()) -> test_return().
108141
unknown_test(_C) ->
109142
ID = <<"unknown_id">>,

apps/ff_server/test/ff_withdrawal_session_repair_SUITE.erl

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,72 @@ repair_failed_session_with_failure(C) ->
124124
{failed, #{
125125
code => SessionID
126126
}},
127-
?assertMatch({finished, Expected}, get_session_status(SessionID)).
127+
?assertMatch({finished, Expected}, get_session_status(SessionID)),
128+
timer:sleep(1000),
129+
TraceUrl = <<"http://localhost:8022/traces/internal/withdrawal_session_v2/", SessionID/binary>>,
130+
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
131+
{ok, Body} = hackney:body(Ref),
132+
[
133+
#{
134+
<<"args">> := [#{<<"created">> := _}],
135+
<<"error">> := null,
136+
<<"events">> := [
137+
#{
138+
<<"event_id">> := 1,
139+
<<"event_payload">> := #{<<"created">> := _},
140+
<<"event_timestamp">> := _
141+
}
142+
],
143+
<<"finished">> := _,
144+
<<"otel_trace_id">> := null,
145+
<<"retry_attempts">> := 0,
146+
<<"retry_interval">> := 0,
147+
<<"running">> := _,
148+
<<"scheduled">> := _,
149+
<<"task_id">> := _,
150+
<<"task_metadata">> := #{<<"range">> := #{}},
151+
<<"task_status">> := <<"finished">>,
152+
<<"task_type">> := <<"init">>
153+
},
154+
#{
155+
%% MAYBE io_lib:format instead of json compatible value
156+
<<"error">> := [
157+
<<"exception">>,
158+
<<"error">>,
159+
#{<<"badmatch">> := #{<<"error">> := <<"notfound">>}}
160+
],
161+
<<"task_status">> := <<"error">>,
162+
<<"task_type">> := <<"timeout">>
163+
},
164+
#{
165+
<<"args">> := #{
166+
<<"set_session_result">> := #{<<"failed">> := #{<<"code">> := _}}
167+
},
168+
<<"error">> := null,
169+
<<"events">> := [
170+
#{
171+
<<"event_id">> := 2,
172+
<<"event_payload">> := #{
173+
<<"finished">> := #{<<"failed">> := #{<<"code">> := _}}
174+
},
175+
<<"event_timestamp">> := _
176+
}
177+
],
178+
<<"task_status">> := <<"finished">>,
179+
<<"task_type">> := <<"repair">>
180+
},
181+
#{
182+
%% Error because can`t notify withdrawal machine
183+
<<"error">> := [
184+
<<"exception">>,
185+
<<"error">>,
186+
#{<<"unable_to_finish_session">> := #{<<"error">> := <<"notfound">>}}
187+
],
188+
<<"task_status">> := <<"error">>,
189+
<<"task_type">> := <<"timeout">>
190+
}
191+
] = json:decode(Body),
192+
ok.
128193

129194
%% Internals
130195

compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ services:
133133
environment:
134134
POSTGRES_MULTIPLE_DATABASES: "fistful,bender,dmt,party_management,shumway,liminator"
135135
POSTGRES_PASSWORD: "postgres"
136+
ports:
137+
- "5432:5432"
136138
volumes:
137139
- ./test/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
138140
healthcheck:

rebar.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
0},
7272
{<<"machinery">>,
7373
{git,"https://github.com/valitydev/machinery-erlang.git",
74-
{ref,"052c1d6ec1d2354711d060cbfbeff910410c0907"}},
74+
{ref,"e97c2fda3da414b0449a865e24f1f72ef80517de"}},
7575
0},
7676
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
7777
{<<"mg_proto">>,
@@ -95,7 +95,7 @@
9595
0},
9696
{<<"progressor">>,
9797
{git,"https://github.com/valitydev/progressor.git",
98-
{ref,"662fee014b1e8bccd72ec3a5959c2fd76a299274"}},
98+
{ref,"c55edd1846eaa08774f0ddfd575cec06affc70ac"}},
9999
1},
100100
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.11.0">>},0},
101101
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.9">>},0},

0 commit comments

Comments
 (0)