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
27 changes: 13 additions & 14 deletions apps/prg_machine/src/prg_machine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

-type process_options() :: #{
ns := namespace(),
default_handling_timeout => timeout()
handling_timeout := timeout()
}.

-export_type([
Expand Down Expand Up @@ -299,17 +299,15 @@ process({CallType, BinArgs, Process}, #{ns := NS} = Opts, BinCtx) ->
{error, Exception}
end.

%% Default woody deadline (30s, configurable per namespace via opts), restoring the
%% old hg_progressor behaviour (hg_woody_service_wrapper:ensure_woody_deadline_set/2).
-define(DEFAULT_HANDLING_TIMEOUT, 30000).

ensure_deadline_set(WoodyCtx, Opts) ->
Timeout = maps:get(handling_timeout, Opts),
MaxDeadline = woody_deadline:from_timeout(Timeout),
case woody_context:get_deadline(WoodyCtx) of
undefined ->
Timeout = maps:get(default_handling_timeout, Opts, ?DEFAULT_HANDLING_TIMEOUT),
woody_context:set_deadline(woody_deadline:from_timeout(Timeout), WoodyCtx);
_Set ->
WoodyCtx
woody_context:set_deadline(MaxDeadline, WoodyCtx);
Deadline ->
%% deadline must not exceed the value process_step_timeout from namespace options
woody_context:set_deadline(min(Deadline, MaxDeadline), WoodyCtx)
end.

%% Event-sourcing
Expand Down Expand Up @@ -557,6 +555,7 @@ map_client_error(_Type, _NS, Error) ->
-define(TEST_NS, env_test_ns).
-define(TEST_FF_NS, 'ff/env_test_ns').
-define(TABLE, prg_machine_dispatch).
-define(TEST_TIMEOUT, 5000).

-spec test() -> _.

Expand Down Expand Up @@ -598,7 +597,7 @@ context_binding_scopes_process(Scope) ->
hellgate -> ?TEST_NS;
fistful -> ?TEST_FF_NS
end,
?assertMatch({ok, _}, run_env_hook_process(#{ns => NS})),
?assertMatch({ok, _}, run_env_hook_process(#{ns => NS, handling_timeout => ?TEST_TIMEOUT})),
?assertEqual([{context_bound, Scope}], prg_machine_env_mock_context:events()).

-spec setup_env_hook_test() -> ok.
Expand Down Expand Up @@ -685,7 +684,7 @@ collapse_survives_non_map_aux_state() ->

-spec business_exception_then_signal_does_not_corrupt_aux_state() -> _.
business_exception_then_signal_does_not_corrupt_aux_state() ->
Opts = #{ns => ?AUX_STATE_TEST_NS},
Opts = #{ns => ?AUX_STATE_TEST_NS, handling_timeout => ?TEST_TIMEOUT},
Process0 = #{
process_id => <<"invoice-exception-test">>,
last_event_id => 0,
Expand Down Expand Up @@ -719,7 +718,7 @@ business_exception_then_signal_does_not_corrupt_aux_state() ->

-spec notify_noop_omits_aux_state() -> _.
notify_noop_omits_aux_state() ->
Opts = #{ns => ?AUX_STATE_TEST_NS},
Opts = #{ns => ?AUX_STATE_TEST_NS, handling_timeout => ?TEST_TIMEOUT},
AuxBin = prg_machine_aux_state_test_handler:marshal_aux_state(#{model => initialized}),
Process = #{
process_id => <<"notify-test">>,
Expand Down Expand Up @@ -748,7 +747,7 @@ lookup_unknown_namespace_returns_error() ->

-spec process_unknown_namespace_returns_error() -> _.
process_unknown_namespace_returns_error() ->
Opts = #{ns => unknown_ns},
Opts = #{ns => unknown_ns, handling_timeout => ?TEST_TIMEOUT},
Process = #{
process_id => <<"unknown-ns-test">>,
last_event_id => 0,
Expand All @@ -762,7 +761,7 @@ process_unknown_namespace_returns_error() ->

-spec process_crash_conforms_progressor_exception() -> _.
process_crash_conforms_progressor_exception() ->
Opts = #{ns => ?AUX_STATE_TEST_NS},
Opts = #{ns => ?AUX_STATE_TEST_NS, handling_timeout => ?TEST_TIMEOUT},
Process = #{
process_id => <<"crash-test">>,
last_event_id => 0,
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{fault_detector_proto, {git, "https://github.com/valitydev/fault-detector-proto.git", {branch, "master"}}},
{limiter_proto, {git, "https://github.com/valitydev/limiter-proto.git", {tag, "v2.1.1"}}},
{herd, {git, "https://github.com/wgnet/herd.git", {tag, "1.3.4"}}},
{progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.25"}}},
{progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.27"}}},
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {tag, "v1.1.22"}}},
{fistful_proto, {git, "https://github.com/valitydev/fistful-proto.git", {branch, "master"}}},
{binbase_proto, {git, "https://github.com/valitydev/binbase-proto.git", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
0},
{<<"progressor">>,
{git,"https://github.com/valitydev/progressor.git",
{ref,"8624e58627e33633e6eb72c5b9defb208b06a169"}},
{ref,"cb8ab2d88b4a49bf521647899eb4e72a24d53026"}},
0},
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.11.0">>},0},
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.9">>},0},
Expand Down
Loading