Browse Source

fix(bpapi): Return undefined for unknown API on the node

ieQu1 3 years ago
parent
commit
c2d03838e2
2 changed files with 6 additions and 3 deletions
  1. 5 2
      apps/emqx/src/bpapi/emqx_bpapi.erl
  2. 1 1
      apps/emqx/test/emqx_bpapi_SUITE.erl

+ 5 - 2
apps/emqx/src/bpapi/emqx_bpapi.erl

@@ -69,9 +69,12 @@ start() ->
     announce(emqx).
 
 %% @doc Get maximum version of the backplane API supported by the node
--spec supported_version(node(), api()) -> api_version().
+-spec supported_version(node(), api()) -> api_version() | undefined.
 supported_version(Node, API) ->
-    ets:lookup_element(?TAB, {Node, API}, #?TAB.version).
+    case ets:lookup(?TAB, {Node, API}) of
+        [#?TAB{version = V}] -> V;
+        [] -> undefined
+    end.
 
 %% @doc Get maximum version of the backplane API supported by the
 %% entire cluster

+ 1 - 1
apps/emqx/test/emqx_bpapi_SUITE.erl

@@ -40,7 +40,7 @@ end_per_suite(_Config) ->
 t_max_supported_version(_Config) ->
     ?assertMatch(3, emqx_bpapi:supported_version('fake-node2@localhost', api2)),
     ?assertMatch(2, emqx_bpapi:supported_version(api2)),
-    ?assertError(_, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
+    ?assertMatch(undefined, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
     ?assertError(_, emqx_bpapi:supported_version(nonexistent_api)).
 
 t_announce(Config) ->