test(gcp_pubsub): increase wait timeout and fix falt injection

This commit is contained in:
Zaiming (Stone) Shi 2023-12-20 16:29:45 +01:00
parent fa80c7e436
commit f4286f3208
2 changed files with 19 additions and 6 deletions

View File

@ -428,7 +428,8 @@ do_get_status(ResourceId, Timeout) ->
msg => "ehttpc_health_check_failed", msg => "ehttpc_health_check_failed",
connector => ResourceId, connector => ResourceId,
reason => Reason, reason => Reason,
worker => Worker worker => Worker,
wait_time => Timeout
}), }),
false false
end end

View File

@ -310,7 +310,7 @@ gcp_pubsub_config(Config) ->
io_lib:format( io_lib:format(
"bridges.gcp_pubsub.~s {\n" "bridges.gcp_pubsub.~s {\n"
" enable = true\n" " enable = true\n"
" connect_timeout = 1s\n" " connect_timeout = 5s\n"
" service_account_json = ~s\n" " service_account_json = ~s\n"
" payload_template = ~p\n" " payload_template = ~p\n"
" pubsub_topic = ~s\n" " pubsub_topic = ~s\n"
@ -1404,8 +1404,23 @@ t_failure_no_body(Config) ->
), ),
ok. ok.
kill_gun_process(EhttpcPid) ->
State = ehttpc:get_state(EhttpcPid, minimal),
GunPid = maps:get(client, State),
true = is_pid(GunPid),
_ = exit(GunPid, kill),
ok.
kill_gun_processes(ConnectorResourceId) ->
Pool = ehttpc:workers(ConnectorResourceId),
Workers = lists:map(fun({_, Pid}) -> Pid end, Pool),
%% assert there is at least one pool member
?assertMatch([_ | _], Workers),
lists:foreach(fun(Pid) -> kill_gun_process(Pid) end, Workers).
t_unrecoverable_error(Config) -> t_unrecoverable_error(Config) ->
ActionResourceId = ?config(action_resource_id, Config), ActionResourceId = ?config(action_resource_id, Config),
ConnectorResourceId = ?config(connector_resource_id, Config),
TelemetryTable = ?config(telemetry_table, Config), TelemetryTable = ?config(telemetry_table, Config),
TestPid = self(), TestPid = self(),
FailureNoBodyHandler = FailureNoBodyHandler =
@ -1415,10 +1430,7 @@ t_unrecoverable_error(Config) ->
%% kill the gun process while it's waiting for the %% kill the gun process while it's waiting for the
%% response so we provoke an `{error, _}' response from %% response so we provoke an `{error, _}' response from
%% ehttpc. %% ehttpc.
lists:foreach( ok = kill_gun_processes(ConnectorResourceId),
fun(Pid) -> exit(Pid, kill) end,
[Pid || {_, Pid, _, _} <- supervisor:which_children(gun_sup)]
),
Rep = cowboy_req:reply( Rep = cowboy_req:reply(
200, 200,
#{<<"content-type">> => <<"application/json">>}, #{<<"content-type">> => <<"application/json">>},