Skip to content

Commit

Permalink
test(lb-mode): add test for lb-mode-ifip
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Sep 19, 2024
1 parent 9500e6d commit 5e68c33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 0 additions & 2 deletions include/quicer.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
-ifndef(QUICER_HRL).
-define(QUICER_HRL, true).

-define(DEFAULT_LB_DEV, "eth0").

%%% ========================================
%%% mirror macro from NIF code
%%% ========================================
Expand Down
8 changes: 4 additions & 4 deletions src/quicer_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ open_lib() ->
end,
LBMode =
case application:get_env(quicer, lb_mode, 0) of
?QUICER_LOAD_BALANCING_IFIP_AS_SERVER_ID ->
lb_server_id(ipv4, application:get_env(quicer, lb_dev, ?DEFAULT_LB_DEV));
X ->
X
X when is_integer(X) ->
X;
DevName when is_list(DevName) ->
lb_server_id(ipv4, DevName)
end,
open_lib(#{
load_balacing_mode => LBMode,
Expand Down
20 changes: 20 additions & 0 deletions test/quicer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
tc_lib_registration_1/1,
tc_lib_re_registration/1,
tc_lib_registration_neg/1,
tc_setopt_global_lb_mode_ifip/1,
tc_open_listener_inval_reg/1,

tc_stream_client_init/1,
Expand Down Expand Up @@ -3081,6 +3082,25 @@ tc_stream_get_owner_remote(Config) ->
SPid ! done,
ensure_server_exit_normal(Ref).

tc_setopt_global_lb_mode_ifip(_Config) ->
{ok, _} = application:ensure_all_started(quicer),
true = code:soft_purge(quicer_nif),
true = code:delete(quicer_nif),
%% If test fail ensure we have this netdev
NetDevName =
case os:type() of
{unix, darwin} -> "lo0";
_ -> "lo"
end,
application:set_env(quicer, lb_mode, NetDevName),
quicer:reg_close(),
quicer:close_lib(),
{ok, _} = quicer:open_lib(),
?assertEqual(
{ok, 2},
quicer:getopt(quic_global, load_balacing_mode)
).

%%% ====================
%%% Internal helpers
%%% ====================
Expand Down

0 comments on commit 5e68c33

Please sign in to comment.