From c89f88ab3ec77ebc1cef180e1ae5c9917b4c7b06 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 18 Dec 2012 18:19:29 +0100 Subject: [cover] Don't mark stopped node as lost Nodes that were stopped with cover:stop/1 were marked as lost and would be reconnected if a nodeup was later received for a node with the same name. This has been corrected. --- lib/tools/src/cover.erl | 11 ++++++++-- lib/tools/test/cover_SUITE.erl | 47 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 10f14b0a49..e51763b6ee 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -792,8 +792,15 @@ main_process_loop(State) -> {'DOWN', _MRef, process, {?SERVER,Node}, _Info} -> %% A remote cover_server is down, mark as lost - Nodes = State#main_state.nodes--[Node], - Lost = [Node|State#main_state.lost_nodes], + {Nodes,Lost} = + case lists:member(Node,State#main_state.nodes) of + true -> + N = State#main_state.nodes--[Node], + L = [Node|State#main_state.lost_nodes], + {N,L}; + false -> % node stopped + {State#main_state.nodes,State#main_state.lost_nodes} + end, main_process_loop(State#main_state{nodes=Nodes,lost_nodes=Lost}); {nodeup,Node} -> diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index 3bf1b44af8..fc30b7453a 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -23,7 +23,8 @@ init_per_group/2,end_per_group/2]). -export([start/1, compile/1, analyse/1, misc/1, stop/1, - distribution/1, reconnect/1, die_and_reconnect/1, export_import/1, + distribution/1, reconnect/1, die_and_reconnect/1, + dont_reconnect_after_stop/1, export_import/1, otp_5031/1, eif/1, otp_5305/1, otp_5418/1, otp_6115/1, otp_7095/1, otp_8188/1, otp_8270/1, otp_8273/1, otp_8340/1]). @@ -47,6 +48,7 @@ all() -> undefined -> [start, compile, analyse, misc, stop, distribution, reconnect, die_and_reconnect, + dont_reconnect_after_stop, export_import, otp_5031, eif, otp_5305, otp_5418, otp_6115, otp_7095, otp_8188, otp_8270, otp_8273, otp_8340]; @@ -520,6 +522,49 @@ die_and_reconnect(Config) -> ?t:stop_node(N1), ok. +%% Test that a stopped node is not marked as lost, i.e. that it is not +%% reconnected if it is restarted (OTP-10638) +dont_reconnect_after_stop(Config) -> + DataDir = ?config(data_dir, Config), + ok = file:set_cwd(DataDir), + + {ok,f} = compile:file(f), + + NodeName = cover_SUITE_dont_reconnect_after_stop, + {ok,N1} = ?t:start_node(NodeName,peer, + [{args," -pa " ++ DataDir},{start_cover,false}]), + {ok,f} = cover:compile(f), + {ok,[N1]} = cover:start(nodes()), + + %% A call to check later + rpc:call(N1,f,f1,[]), + + %% Stop cover on the node, then terminate the node + cover:stop(N1), + rpc:call(N1,erlang,halt,[]), + [] = cover:which_nodes(), + + check_f_calls(1,0), + + %% Restart the node and check that cover does not reconnect + {ok,N1} = ?t:start_node(NodeName,peer, + [{args," -pa " ++ DataDir},{start_cover,false}]), + timer:sleep(300), + [] = cover:which_nodes(), + Beam = rpc:call(N1,code,which,[f]), + false = (Beam==cover_compiled), + + %% One more call... + rpc:call(N1,f,f1,[]), + cover:flush(N1), + + %% Ensure that the last call is not counted + check_f_calls(1,0), + + cover:stop(), + ?t:stop_node(N1), + ok. + export_import(suite) -> []; export_import(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir, Config), -- cgit v1.2.3 From c1ecd14be890ec4f2e8a25f00525412a381fcc72 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 19 Dec 2012 12:25:07 +0100 Subject: [cover] Remove stopped node also from lost_nodes list A nodes that was stopped with cover:stop/1 while marked as lost would not be removed from the list of lost nodes. Therefore, if a nodeup was later received for a node with the same name, it would be reconnected. This has been corrected. --- lib/tools/src/cover.erl | 4 +++- lib/tools/test/cover_SUITE.erl | 50 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index e51763b6ee..943eee20d2 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -705,7 +705,9 @@ main_process_loop(State) -> remote_collect('_',Nodes,true), reply(From, ok), Nodes1 = State#main_state.nodes--Nodes, - main_process_loop(State#main_state{nodes=Nodes1}); + LostNodes1 = State#main_state.lost_nodes--Nodes, + main_process_loop(State#main_state{nodes=Nodes1, + lost_nodes=LostNodes1}); {From, {flush,Nodes}} -> remote_collect('_',Nodes,false), diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index fc30b7453a..9d2b449460 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -24,7 +24,8 @@ -export([start/1, compile/1, analyse/1, misc/1, stop/1, distribution/1, reconnect/1, die_and_reconnect/1, - dont_reconnect_after_stop/1, export_import/1, + dont_reconnect_after_stop/1, stop_node_after_disconnect/1, + export_import/1, otp_5031/1, eif/1, otp_5305/1, otp_5418/1, otp_6115/1, otp_7095/1, otp_8188/1, otp_8270/1, otp_8273/1, otp_8340/1]). @@ -48,7 +49,7 @@ all() -> undefined -> [start, compile, analyse, misc, stop, distribution, reconnect, die_and_reconnect, - dont_reconnect_after_stop, + dont_reconnect_after_stop, stop_node_after_disconnect, export_import, otp_5031, eif, otp_5305, otp_5418, otp_6115, otp_7095, otp_8188, otp_8270, otp_8273, otp_8340]; @@ -565,6 +566,51 @@ dont_reconnect_after_stop(Config) -> ?t:stop_node(N1), ok. +%% Test that a node which is stopped while it is marked as lost is not +%% reconnected if it is restarted (OTP-10638) +stop_node_after_disconnect(Config) -> + DataDir = ?config(data_dir, Config), + ok = file:set_cwd(DataDir), + + {ok,f} = compile:file(f), + + NodeName = cover_SUITE_stop_node_after_disconnect, + {ok,N1} = ?t:start_node(NodeName,peer, + [{args," -pa " ++ DataDir},{start_cover,false}]), + {ok,f} = cover:compile(f), + {ok,[N1]} = cover:start(nodes()), + + %% A call to check later + rpc:call(N1,f,f1,[]), + + %% Flush the node, then terminate the node to make it marked as lost + cover:flush(N1), + rpc:call(N1,erlang,halt,[]), + + check_f_calls(1,0), + + %% Stop cover on node + cover:stop(N1), + + %% Restart the node and check that cover does not reconnect + {ok,N1} = ?t:start_node(NodeName,peer, + [{args," -pa " ++ DataDir},{start_cover,false}]), + timer:sleep(300), + [] = cover:which_nodes(), + Beam = rpc:call(N1,code,which,[f]), + false = (Beam==cover_compiled), + + %% One more call... + rpc:call(N1,f,f1,[]), + cover:flush(N1), + + %% Ensure that the last call is not counted + check_f_calls(1,0), + + cover:stop(), + ?t:stop_node(N1), + ok. + export_import(suite) -> []; export_import(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir, Config), -- cgit v1.2.3 From f6eb49df376b56f746c2e74d8cf159261aee5464 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 19 Dec 2012 14:07:25 +0100 Subject: [cover] Fix timing dependent bug in cover_SUITE:reconnect Adding a timer:sleep between these two lines: net_kernel:disconnect(N1), [] = cover:which_nodes(), This is to make sure the disconnect is detected by cover before checking that the node is gone. --- lib/tools/test/cover_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tools') diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index 9d2b449460..ef3daef173 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -450,8 +450,8 @@ reconnect(Config) -> %% Disconnect and check that node is removed from main cover node net_kernel:disconnect(N1), + timer:sleep(500), % allow some to detect disconnect and for f:f2() call [] = cover:which_nodes(), - timer:sleep(500), % allow some time for the f:f2() call %% Do some add one module (b) and remove one module (a) code:purge(a), -- cgit v1.2.3 From 06ad426384ab6c5f5966c4f5ae87be0fb01f346c Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 21 Dec 2012 12:16:39 +0100 Subject: [cover] Cleanup by stopping cover between tests If one test failed, the next would sometimes also fail since cover was not stopped. --- lib/tools/test/cover_SUITE.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index ef3daef173..57260a3869 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -89,8 +89,11 @@ init_per_testcase(TC, Config) when TC =:= misc; init_per_testcase(_TestCase, Config) -> Config. -end_per_testcase(_TestCase, _Config) -> - %cover:stop(), +end_per_testcase(TestCase, _Config) -> + case lists:member(TestCase,[start,compile,analyse,misc]) of + true -> ok; + false -> cover:stop() + end, ok. start(suite) -> []; @@ -999,7 +1002,7 @@ otp_8270(Config) when is_list(Config) -> ok. otp_8273(doc) -> - ["OTP-8270. Bug."]; + ["OTP-8273. Bug."]; otp_8273(suite) -> []; otp_8273(Config) when is_list(Config) -> Test = <<"-module(t). -- cgit v1.2.3