Ver código fonte

test(router): also verify helper schedules reconcile correctly

Andrew Mayorov 1 ano atrás
pai
commit
bcacbb8c55

+ 9 - 0
apps/emqx/src/emqx_router_helper.erl

@@ -64,6 +64,15 @@
 %% This is a fallback, left node is expected to be purged right away.
 %% This is a fallback, left node is expected to be purged right away.
 -define(PURGE_LEFT_TIMEOUT, 15_000).
 -define(PURGE_LEFT_TIMEOUT, 15_000).
 
 
+-ifdef(TEST).
+-undef(RECONCILE_INTERVAL).
+-undef(PURGE_DEAD_TIMEOUT).
+-undef(PURGE_LEFT_TIMEOUT).
+-define(RECONCILE_INTERVAL, {2_000, '±', 500}).
+-define(PURGE_DEAD_TIMEOUT, 3_000).
+-define(PURGE_LEFT_TIMEOUT, 1_000).
+-endif.
+
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% Mnesia bootstrap
 %% Mnesia bootstrap
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------

+ 7 - 6
apps/emqx/test/emqx_router_helper_SUITE.erl

@@ -168,13 +168,14 @@ t_cluster_node_down(Config) ->
     emqx_router:add_route(<<"down/b/#">>, ClusterNode),
     emqx_router:add_route(<<"down/b/#">>, ClusterNode),
     emqx_router:add_route(<<"test/e/f">>, node()),
     emqx_router:add_route(<<"test/e/f">>, node()),
     ?assertMatch([_, _], emqx_router:topics()),
     ?assertMatch([_, _], emqx_router:topics()),
-    ok = emqx_cth_cluster:stop([ClusterNode]),
-    {scheduled, {ok, _}} = ?wait_async_action(
-        %% The same as what would have happened after dead node timeout had passed.
-        emqx_router_helper:purge_force(),
-        #{?snk_kind := emqx_router_node_purged, node := ClusterNode},
-        3_000
+    {ok, SRef} = snabbkaffe:subscribe(
+        %% Should be purged after ~2 reconciliations.
+        ?match_event(#{?snk_kind := emqx_router_node_purged, node := ClusterNode}),
+        1,
+        10_000
     ),
     ),
+    ok = emqx_cth_cluster:stop([ClusterNode]),
+    {ok, _Event} = snabbkaffe:receive_events(SRef),
     ?assertEqual([<<"test/e/f">>], emqx_router:topics()).
     ?assertEqual([<<"test/e/f">>], emqx_router:topics()).
 
 
 t_cluster_node_restart('init', Config) ->
 t_cluster_node_restart('init', Config) ->