From ab662f506dc438d9fcac4aae8db9753a2bd75e56 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 10 Oct 2023 09:50:09 -0300 Subject: [PATCH] test: attempt to fix flaky http bridge suite ``` =CRASH REPORT==== 10-Oct-2023::05:35:30.911371 === crasher: initial call: ehttpc:init/1 pid: <0.23358.2> registered_name: [] exception error: bad argument in function persistent_term:get/1 called as persistent_term:get({emqx_bridge_http_SUITE, do_t_async_retries,attempts}) *** argument 1: no persistent term stored with this key in call from emqx_bridge_http_SUITE:'-do_t_async_retries/3-fun-2-'/0 (/__w/emqx/emqx/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl, line 697) in call from emqx_bridge_http_SUITE:'-do_t_async_retries/3-fun-4-'/6 (/__w/emqx/emqx/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl, line 705) ``` --- .../test/emqx_bridge_http_SUITE.erl | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl b/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl index 5395460b8..6fdd0e0d5 100644 --- a/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl +++ b/apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl @@ -429,8 +429,8 @@ t_async_free_retries(Config) -> ), ?assertEqual(ExpectedAttempts, Get(), #{error => Error}) end, - do_t_async_retries(Context, {error, normal}, Fn), - do_t_async_retries(Context, {error, {shutdown, normal}}, Fn), + do_t_async_retries(?FUNCTION_NAME, Context, {error, normal}, Fn), + do_t_async_retries(?FUNCTION_NAME, Context, {error, {shutdown, normal}}, Fn), ok. t_async_common_retries(Config) -> @@ -465,10 +465,12 @@ t_async_common_retries(Config) -> end, %% These two succeed because they're further retried by the buffer %% worker synchronously, and we're not mock that call. - do_t_async_retries(Context, {error, {closed, "The connection was lost."}}, FnSucceed), - do_t_async_retries(Context, {error, {shutdown, closed}}, FnSucceed), + do_t_async_retries( + ?FUNCTION_NAME, Context, {error, {closed, "The connection was lost."}}, FnSucceed + ), + do_t_async_retries(?FUNCTION_NAME, Context, {error, {shutdown, closed}}, FnSucceed), %% This fails because this error is treated as unrecoverable. - do_t_async_retries(Context, {error, something_else}, FnFail), + do_t_async_retries(?FUNCTION_NAME, Context, {error, something_else}, FnFail), ok. t_bad_bridge_config(_Config) -> @@ -688,14 +690,15 @@ t_bridge_probes_header_atoms(Config) -> ok. %% helpers -do_t_async_retries(TestContext, Error, Fn) -> +do_t_async_retries(TestCase, TestContext, Error, Fn) -> #{error_attempts := ErrorAttempts} = TestContext, - persistent_term:put({?MODULE, ?FUNCTION_NAME, attempts}, 0), - on_exit(fun() -> persistent_term:erase({?MODULE, ?FUNCTION_NAME, attempts}) end), - Get = fun() -> persistent_term:get({?MODULE, ?FUNCTION_NAME, attempts}) end, + PTKey = {?MODULE, TestCase, attempts}, + persistent_term:put(PTKey, 0), + on_exit(fun() -> persistent_term:erase(PTKey) end), + Get = fun() -> persistent_term:get(PTKey) end, GetAndBump = fun() -> - Attempts = persistent_term:get({?MODULE, ?FUNCTION_NAME, attempts}), - persistent_term:put({?MODULE, ?FUNCTION_NAME, attempts}, Attempts + 1), + Attempts = persistent_term:get(PTKey), + persistent_term:put(PTKey, Attempts + 1), Attempts + 1 end, emqx_common_test_helpers:with_mock( @@ -714,6 +717,7 @@ do_t_async_retries(TestContext, Error, Fn) -> end, fun() -> Fn(Get, Error) end ), + persistent_term:erase(PTKey), ok. receive_request_notifications(MessageIDs, _ResponseDelay, _Acc) when map_size(MessageIDs) =:= 0 ->