Skip to content

Commit 6edca81

Browse files
Merge pull request erlang#5566 from max-au/max-au/peerify-tools
[tools] replace test_server:start_node with ?CT_PEER()
2 parents b7e4ff9 + ccc3ee8 commit 6edca81

File tree

4 files changed

+62
-97
lines changed

4 files changed

+62
-97
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ TAGS
1010
# vscode
1111
.vscode
1212

13+
# IntelliJ IDEA
14+
.idea
15+
1316
autom4te.cache
1417
*.beam
1518
*.asn1db

lib/common_test/src/test_server.erl

+3-1
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,9 @@ start_peer(#{name := Name} = Opts, Module) ->
28342834
end,
28352835
FullArgs = CookieArg ++ ["-pa", filename:dirname(code:which(Module)),
28362836
"-env", "ERL_CRASH_DUMP", CrashFile] ++ Args,
2837-
case test_server:is_cover() of
2837+
%% start_cover => false is intentionally undocumented, and is not
2838+
%% expected to be used by anything but cover_SUITE test.
2839+
case maps:get(start_cover, Opts, true) andalso test_server:is_cover() of
28382840
true ->
28392841
%% when cover is active, node must shut down gracefully, otherwise
28402842
%% coverage information won't be sent to cover master

lib/tools/test/cover_SUITE.erl

+48-69
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
suite() ->
2727
[{ct_hooks,[ts_install_cth]},
28-
{timetrap,{minutes,5}}].
28+
{timetrap,{minutes,2}}].
2929

3030
all() ->
3131
NoStartStop = [eif,otp_5305,otp_5418,otp_7095,otp_8273,
@@ -441,14 +441,14 @@ distribution(Config) when is_list(Config) ->
441441
DataDir = proplists:get_value(data_dir, Config),
442442
ok = file:set_cwd(DataDir),
443443

444-
{ok,N1} = test_server:start_node(cover_SUITE_distribution1,slave,[]),
445-
{ok,N2} = test_server:start_node(cover_SUITE_distribution2,slave,[]),
446-
{ok,N3} = test_server:start_node(cover_SUITE_distribution3,slave,[]),
447-
{ok,N4} = test_server:start_node(cover_SUITE_distribution4,slave,[]),
444+
{ok,P1,N1} = ?CT_PEER(),
445+
{ok,P2,N2} = ?CT_PEER(),
446+
{ok,P3,N3} = ?CT_PEER(),
447+
{ok,P4,N4} = ?CT_PEER(),
448448

449449
%% Check that an already compiled module is loaded on new nodes
450450
{ok,f} = cover:compile(f),
451-
{ok,[_,_,_,_]} = cover:start(nodes()),
451+
{ok,[_,_,_,_]} = cover:start([N1,N2,N3,N4]),
452452
cover_compiled = code:which(f),
453453
cover_compiled = rpc:call(N1,code,which,[f]),
454454
cover_compiled = rpc:call(N2,code,which,[f]),
@@ -475,7 +475,7 @@ distribution(Config) when is_list(Config) ->
475475

476476
%% this is lost when the node is killed
477477
rpc:call(N3,f,f2,[]),
478-
rpc:call(N3,erlang,halt,[]),
478+
peer:stop(P3),
479479

480480
%% this should be visible in analyse
481481
rpc:call(N1,f,f1,[]),
@@ -515,7 +515,7 @@ distribution(Config) when is_list(Config) ->
515515
%% Check that flush collects data so calls are not lost if node is killed
516516
rpc:call(N4,f,f2,[]),
517517
ok = cover:flush(N4),
518-
rpc:call(N4,erlang,halt,[]),
518+
peer:stop(P4),
519519
check_f_calls(1,3),
520520

521521
%% Check that stop() unloads on all nodes
@@ -536,8 +536,8 @@ distribution(Config) when is_list(Config) ->
536536
%% Cleanup
537537
Files = lsfiles(),
538538
remove(files(Files, ".beam")),
539-
test_server:stop_node(N1),
540-
test_server:stop_node(N2).
539+
peer:stop(P1),
540+
peer:stop(P2).
541541

542542
%% Test that a lost node is reconnected
543543
reconnect(Config) ->
@@ -548,12 +548,10 @@ reconnect(Config) ->
548548
{ok,b} = compile:file(b),
549549
{ok,f} = compile:file(f),
550550

551-
{ok,N1} = test_server:start_node(cover_SUITE_reconnect,peer,
552-
[{args," -pa " ++ DataDir},
553-
{start_cover,false}]),
551+
{ok,P1,N1} = ?CT_PEER(#{connection => 0, args => ["-pa", DataDir]}),
554552
{ok,a} = cover:compile(a),
555553
{ok,f} = cover:compile(f),
556-
{ok,[N1]} = cover:start(nodes()),
554+
{ok,[N1]} = cover:start([N1]),
557555

558556
%% Some calls to check later
559557
rpc:call(N1,f,f1,[]),
@@ -591,7 +589,7 @@ reconnect(Config) ->
591589
check_f_calls(2,1),
592590

593591
cover:stop(),
594-
test_server:stop_node(N1),
592+
peer:stop(P1),
595593
ok.
596594

597595
%% Test that a lost node is reconnected - also if it has been dead
@@ -601,29 +599,24 @@ die_and_reconnect(Config) ->
601599

602600
{ok,f} = compile:file(f),
603601

604-
NodeName = cover_SUITE_die_and_reconnect,
605-
{ok,N1} = test_server:start_node(NodeName,peer,
606-
[{args," -pa " ++ DataDir},
607-
{start_cover,false}]),
602+
{ok, P1, N1} = ?CT_PEER(#{name => ?CT_PEER_NAME(), args => ["-pa", DataDir]}),
608603
%% {ok,a} = cover:compile(a),
609604
{ok,f} = cover:compile(f),
610-
{ok,[N1]} = cover:start(nodes()),
605+
{ok,[N1]} = cover:start([N1]),
611606

612607
%% Some calls to check later
613608
rpc:call(N1,f,f1,[]),
614609
cover:flush(N1),
615610
rpc:call(N1,f,f1,[]),
616611

617612
%% Kill the node
618-
rpc:call(N1,erlang,halt,[]),
613+
peer:stop(P1),
619614
cover_which_nodes([]),
620615

621616
check_f_calls(1,0), % only the first call - before the flush
622617

623618
%% Restart the node and check that cover reconnects
624-
{ok,N1} = test_server:start_node(NodeName,peer,
625-
[{args," -pa " ++ DataDir},
626-
{start_cover,false}]),
619+
{ok,P2,N1} = ?CT_PEER(#{name => N1, args => ["-pa", DataDir]}),
627620
timer:sleep(100),
628621
[N1] = cover:which_nodes(), % we are reconnected
629622
cover_compiled = rpc:call(N1,code,which,[f]),
@@ -635,7 +628,7 @@ die_and_reconnect(Config) ->
635628
check_f_calls(2,0),
636629

637630
cover:stop(),
638-
test_server:stop_node(N1),
631+
peer:stop(P2),
639632
ok.
640633

641634
%% Test that a stopped node is not marked as lost, i.e. that it is not
@@ -646,27 +639,23 @@ dont_reconnect_after_stop(Config) ->
646639

647640
{ok,f} = compile:file(f),
648641

649-
NodeName = cover_SUITE_dont_reconnect_after_stop,
650-
{ok,N1} = test_server:start_node(NodeName,peer,
651-
[{args," -pa " ++ DataDir},
652-
{start_cover,false}]),
642+
{ok, P1, N1} = ?CT_PEER(#{name => ?CT_PEER_NAME(), args => ["-pa", DataDir],
643+
start_cover => false}),
653644
{ok,f} = cover:compile(f),
654-
{ok,[N1]} = cover:start(nodes()),
645+
{ok,[N1]} = cover:start([N1]),
655646

656647
%% A call to check later
657648
rpc:call(N1,f,f1,[]),
658649

659650
%% Stop cover on the node, then terminate the node
660651
cover:stop(N1),
661-
rpc:call(N1,erlang,halt,[]),
652+
peer:stop(P1),
662653
cover_which_nodes([]),
663654

664655
check_f_calls(1,0),
665656

666657
%% Restart the node and check that cover does not reconnect
667-
{ok,N1} = test_server:start_node(NodeName,peer,
668-
[{args," -pa " ++ DataDir},
669-
{start_cover,false}]),
658+
{ok, P2, N1} = ?CT_PEER(#{name => N1, args => ["-pa", DataDir], start_cover => false}),
670659
timer:sleep(300),
671660
cover_which_nodes([]),
672661
Beam = rpc:call(N1,code,which,[f]),
@@ -680,7 +669,7 @@ dont_reconnect_after_stop(Config) ->
680669
check_f_calls(1,0),
681670

682671
cover:stop(),
683-
test_server:stop_node(N1),
672+
peer:stop(P2),
684673
ok.
685674

686675
%% Test that a node which is stopped while it is marked as lost is not
@@ -691,29 +680,25 @@ stop_node_after_disconnect(Config) ->
691680

692681
{ok,f} = compile:file(f),
693682

694-
NodeName = cover_SUITE_stop_node_after_disconnect,
695-
{ok,N1} = test_server:start_node(NodeName,peer,
696-
[{args," -pa " ++ DataDir},
697-
{start_cover,false}]),
683+
{ok, P1, N1} = ?CT_PEER(#{name => ?CT_PEER_NAME(), args => ["-pa", DataDir],
684+
start_cover => false}),
698685
{ok,f} = cover:compile(f),
699-
{ok,[N1]} = cover:start(nodes()),
686+
{ok,[N1]} = cover:start([N1]),
700687

701688
%% A call to check later
702689
rpc:call(N1,f,f1,[]),
703690

704691
%% Flush the node, then terminate the node to make it marked as lost
705692
cover:flush(N1),
706-
rpc:call(N1,erlang,halt,[]),
693+
peer:stop(P1),
707694

708695
check_f_calls(1,0),
709696

710697
%% Stop cover on node
711698
cover:stop(N1),
712699

713700
%% Restart the node and check that cover does not reconnect
714-
{ok,N1} = test_server:start_node(NodeName,peer,
715-
[{args," -pa " ++ DataDir},
716-
{start_cover,false}]),
701+
{ok, P2, N1} = ?CT_PEER(#{name => N1, args => ["-pa", DataDir], start_cover => false}),
717702
timer:sleep(300),
718703
cover_which_nodes([]),
719704
Beam = rpc:call(N1,code,which,[f]),
@@ -727,7 +712,7 @@ stop_node_after_disconnect(Config) ->
727712
check_f_calls(1,0),
728713

729714
cover:stop(),
730-
test_server:stop_node(N1),
715+
peer:stop(P2),
731716
ok.
732717

733718
distribution_performance(Config) ->
@@ -743,18 +728,14 @@ distribution_performance(Config) ->
743728

744729
% test_server:break(""),
745730

746-
NodeName = cover_SUITE_distribution_performance,
747-
{ok,N1} = test_server:start_node(NodeName,peer,[{start_cover,false}]),
731+
{ok, P1, N1} = ?CT_PEER(),
748732
%% CFun = fun() ->
749733
%% [{ok,_} = cover:compile_beam(Mod) || Mod <- Mods]
750734
%% end,
751735
CFun = fun() -> cover:compile_beam(Mods) end,
752-
{CT,_CA} = timer:tc(CFun),
753-
% erlang:display(_CA),
754-
erlang:display({compile,CT}),
736+
{_CT, _CA} = timer:tc(CFun),
755737

756-
{SNT,_} = timer:tc(fun() -> {ok,[N1]} = cover:start(nodes()) end),
757-
erlang:display({start_node,SNT}),
738+
{ok,[N1]} = cover:start([N1]),
758739

759740
[1 = rpc:call(N1,Mod,f1,[1]) || Mod <- Mods],
760741

@@ -770,16 +751,14 @@ distribution_performance(Config) ->
770751

771752
% Fun = fun() -> cover:reset() end,
772753

773-
{AT,_A} = timer:tc(Fun),
774-
erlang:display({analyse,AT}),
754+
{_AT, _A} = timer:tc(Fun),
775755
% erlang:display(lists:sort([X || X={_MFA,N} <- lists:append([L || {ok,L}<-A]), N=/=0])),
776756

777757
%% fprof:apply(Fun, [],[{procs,[whereis(cover_server)]}]),
778758
%% fprof:profile(),
779759
%% fprof:analyse(dest,[]),
780760

781-
{SNT2,_} = timer:tc(fun() -> test_server:stop_node(N1) end),
782-
erlang:display({stop_node,SNT2}),
761+
peer:stop(P1),
783762

784763
code:del_path(Dir),
785764
Files = filelib:wildcard(AllFiles),
@@ -947,11 +926,11 @@ export_import(Config) when is_list(Config) ->
947926
otp_5031(Config) when is_list(Config) ->
948927
ct:timetrap({seconds, 10}),
949928

950-
{ok,N1} = test_server:start_node(cover_SUITE_otp_5031,slave,[]),
929+
{ok,Peer,N1} = ?CT_PEER(),
951930
{ok,[N1]} = cover:start(N1),
952931
{error,not_main_node} = rpc:call(N1,cover,modules,[]),
953932
cover:stop(),
954-
test_server:stop_node(N1),
933+
peer:stop(Peer),
955934
ok.
956935

957936
%% Test the \'Exclude Included Functions\' functionality
@@ -1160,13 +1139,13 @@ otp_8270(Config) when is_list(Config) ->
11601139

11611140
PrivDir = proplists:get_value(priv_dir, Config),
11621141

1163-
As = [{args," -pa " ++ PrivDir}],
1164-
{ok,N1} = test_server:start_node(cover_n1,slave,As),
1165-
{ok,N2} = test_server:start_node(cover_n2,slave,As),
1166-
{ok,N3} = test_server:start_node(cover_n3,slave,As),
1142+
As = ["-pa", PrivDir],
1143+
{ok,P1,N1} = ?CT_PEER(As),
1144+
{ok,P2,N2} = ?CT_PEER(As),
1145+
{ok,P3,N3} = ?CT_PEER(As),
11671146

11681147
timer:sleep(500),
1169-
{ok,[_,_,_]} = cover:start(nodes()),
1148+
{ok,[_,_,_]} = cover:start([N1,N2,N3]),
11701149

11711150
Test = <<"-module(m).\n"
11721151
"-compile(export_all).\n"
@@ -1204,9 +1183,9 @@ otp_8270(Config) when is_list(Config) ->
12041183
{N3,true} = {N3,is_list(N3_info)},
12051184

12061185
exit(Pid1,kill),
1207-
test_server:stop_node(N1),
1208-
test_server:stop_node(N2),
1209-
test_server:stop_node(N3),
1186+
peer:stop(P1),
1187+
peer:stop(P2),
1188+
peer:stop(P3),
12101189
ok.
12111190

12121191
%% OTP-8273. Bug.
@@ -1608,7 +1587,7 @@ cover_clauses(Config) when is_list(Config) ->
16081587
-export([clauses/0]).
16091588
clauses() -> ok.
16101589
">>,
1611-
File = cc_mod(cover_clauses, Test, Config),
1590+
_File = cc_mod(cover_clauses, Test, Config),
16121591
ok.
16131592

16141593
%% Take compiler options from beam in cover:compile_beam
@@ -1836,9 +1815,9 @@ local_only(Config) ->
18361815

18371816
%% Make sure that it is not possible to run cover on
18381817
%% slave nodes.
1839-
{ok,Name} = test_server:start_node(?FUNCTION_NAME, slave, []),
1818+
{ok,Peer,Name} = ?CT_PEER(),
18401819
{error,local_only} = cover:start([Name]),
1841-
test_server:stop_node(Name),
1820+
peer:stop(Peer),
18421821
ok.
18431822

18441823
%% ERL-943; We should not crash on startup when multiple servers race to

0 commit comments

Comments
 (0)