From 9ff53f4293615a1c868758e7c88692b4bd6ee707 Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Mon, 11 Mar 2024 13:03:13 +0100 Subject: [PATCH] test(conf): fix flaky config sync testcases Before the recent changes these testcases relied on the fact that peer nodes that are part of the test cluster are started one after the other. This is now not the case in general with `emqx_cth_cluster`, so now we need to additionally find the "longest running node" in the cluster before running test logic. --- apps/emqx_conf/test/emqx_conf_app_SUITE.erl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/emqx_conf/test/emqx_conf_app_SUITE.erl b/apps/emqx_conf/test/emqx_conf_app_SUITE.erl index 4760cbed3..9687e337d 100644 --- a/apps/emqx_conf/test/emqx_conf_app_SUITE.erl +++ b/apps/emqx_conf/test/emqx_conf_app_SUITE.erl @@ -64,7 +64,8 @@ t_copy_new_data_dir(Config) -> ), %% 1. Start all nodes - [First | Rest] = Nodes = start_cluster(Cluster), + Nodes = start_cluster(Cluster), + [First | Rest] = sort_highest_uptime(Nodes), try NodeDataDir = erpc:call(First, emqx, data_dir, []), File = NodeDataDir ++ "/configs/cluster.hocon", @@ -88,7 +89,8 @@ t_copy_deprecated_data_dir(Config) -> ), %% 1. Start all nodes - [First | Rest] = Nodes = start_cluster(Cluster), + Nodes = start_cluster(Cluster), + [First | Rest] = sort_highest_uptime(Nodes), try NodeDataDir = erpc:call(First, emqx, data_dir, []), File = NodeDataDir ++ "/configs/cluster-override.conf", @@ -246,3 +248,11 @@ cluster(TC, Specs, Config) -> cluster_spec({Type, Num}) -> {Type, list_to_atom(atom_to_list(?MODULE) ++ integer_to_list(Num))}. + +sort_highest_uptime(Nodes) -> + Ranking = lists:sort([{-get_node_uptime(N), N} || N <- Nodes]), + element(2, lists:unzip(Ranking)). + +get_node_uptime(Node) -> + {Milliseconds, _} = erpc:call(Node, erlang, statistics, [wall_clock]), + Milliseconds.