Przeglądaj źródła

Fix the coverage shaky (#2010)

Gilbert 7 lat temu
rodzic
commit
295a9d692e
2 zmienionych plików z 11 dodań i 1 usunięć
  1. 5 0
      src/emqx_broker.erl
  2. 6 1
      test/emqx_broker_SUITE.erl

+ 5 - 0
src/emqx_broker.erl

@@ -33,6 +33,11 @@
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
          code_change/3]).
 
+-ifdef(TEST).
+-compile(export_all).
+-compile(nowarn_export_all).
+-endif.
+
 -record(state, {pool, id, submap, submon}).
 -record(subscribe, {topic, subpid, subid, subopts = #{}}).
 -record(unsubscribe, {topic, subpid, subid}).

+ 6 - 1
test/emqx_broker_SUITE.erl

@@ -38,6 +38,7 @@ groups() ->
                            publish, pubsub,
                            t_local_subscribe,
                            t_shared_subscribe,
+                           dispatch_with_no_sub,
                            'pubsub#', 'pubsub+']},
      {session, [sequence], [start_session]},
      {metrics, [sequence], [inc_dec_metric]},
@@ -76,6 +77,11 @@ publish(_) ->
     emqx:publish(Msg),
     ?assert(receive {dispatch, <<"test/+">>, Msg} -> true after 5 -> false end).
 
+dispatch_with_no_sub(_) ->
+    Msg = emqx_message:make(ct, <<"no_subscribers">>, <<"hello">>),
+    Delivery = #delivery{sender = self(), message = Msg, results = []},
+    ?assertEqual(Delivery, emqx_broker:route([{<<"no_subscribers">>, node()}], Delivery)).
+
 pubsub(_) ->
     true = emqx:is_running(node()),
     Self = self(),
@@ -193,4 +199,3 @@ set_alarms(_) ->
     ?assertEqual(1, length(Alarms)),
     emqx_alarm_mgr:clear_alarm(<<"1">>),
     [] = emqx_alarm_mgr:get_alarms().
-