diff --git a/apps/emqx_auth_mongo/test/emqx_auth_mongo_SUITE.erl b/apps/emqx_auth_mongo/test/emqx_auth_mongo_SUITE.erl index 7a7f98a3d..dc487891c 100644 --- a/apps/emqx_auth_mongo/test/emqx_auth_mongo_SUITE.erl +++ b/apps/emqx_auth_mongo/test/emqx_auth_mongo_SUITE.erl @@ -340,7 +340,7 @@ t_available(Config) -> ?assertEqual( {error, {mongo_error, 2}}, emqx_auth_mongo:available(Pool, SuperCollection, EmptySelector, fun error_code_query/3)), - %% exception. + %% exception (in query) ?assertMatch( {error, _}, with_failure(down, ProxyHost, ProxyPort, @@ -349,6 +349,16 @@ t_available(Config) -> Selector = #{}, emqx_auth_mongo:available(Pool, Collection, Selector) end)), + %% exception (arbitrary function) + ?assertMatch( + {error, _}, + with_failure(down, ProxyHost, ProxyPort, + fun() -> + Collection = <<"mqtt_user">>, + Selector = #{}, + RaisingFun = fun(_, _, _) -> error(some_error) end, + emqx_auth_mongo:available(Pool, Collection, Selector, RaisingFun) + end)), ok. t_check_acl(_) -> @@ -430,6 +440,19 @@ t_available_acl_query_timeout(Config) -> ct:timetrap(90000), test_acl_query_failure(timeout, Config). +%% checks that `with_timeout' lets unknown errors pass through +t_query_multi_unknown_exception(_Config) -> + ok = meck:new(ecpool, [no_link, no_history, non_strict, passthrough]), + ok = meck:expect(ecpool, with_client, fun(_, _) -> throw(some_error) end), + Pool = ?APP, + Collection = ?MONGO_CL_ACL, + SelectorList = [#{<<"username">> => <<"user">>}], + try + ?assertThrow(some_error, emqx_auth_mongo:query_multi(Pool, Collection, SelectorList)) + after + meck:unload(ecpool) + end. + t_acl_superuser_no_connection(Config) -> ProxyHost = ?config(proxy_host, Config), ProxyPort = ?config(proxy_port, Config),