1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1996-2020. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20-module(pool_SUITE).
21
22-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
23	 init_per_group/2,end_per_group/2]).
24-export([basic/1, link_race/1, echo/1]).
25
26suite() -> [{ct_hooks,[{ts_install_cth,[{nodenames, 1}]}]}].
27
28all() ->
29    [basic, link_race].
30
31groups() ->
32    [].
33
34init_per_suite(Config) ->
35    Config.
36
37end_per_suite(_Config) ->
38    ok.
39
40init_per_group(_GroupName, Config) ->
41    Config.
42
43end_per_group(_GroupName, Config) ->
44    Config.
45
46basic(Config) ->
47
48    {ok, Node, PoolNode} = init_pool(pool_SUITE_basic, basic, Config),
49
50    Node = rpc:call(Node, pool, get_node, []),
51    PoolNode = rpc:call(Node, pool, get_node, []),
52
53    do_echo(Node),
54    do_echo(Node),
55
56    test_server:stop_node(Node),
57    ok.
58
59link_race(Config) ->
60
61    {ok, Node, PoolNode} = init_pool(pool_SUITE_basic, basic, Config),
62
63    Node = rpc:call(Node, pool, get_node, []),
64    PoolNode = rpc:call(Node, pool, get_node, []),
65
66    rpc:call(Node, pool, pspawn_link, [erlang, is_atom, [?MODULE]]),
67
68    test_server:stop_node(Node),
69    ok.
70
71do_echo(Node) ->
72    EchoPid = rpc:call(Node, pool, pspawn, [?MODULE, echo, [self()]]),
73    Ref = EchoPid ! make_ref(),
74    receive Ref -> ok after 1000 -> ct:fail(receive M -> M after 0 -> timeout end) end.
75
76echo(Parent) ->
77    receive Msg ->
78            Parent ! Msg
79    end.
80
81
82init_pool(Proxy, Name, Config) ->
83    PrivDir = proplists:get_value(priv_dir, Config),
84    [Slave] = proplists:get_value(nodenames, Config),
85    {ok, Node} = test_server:start_node(Proxy, slave, []),
86    {ok, Hostname} = inet:gethostname(),
87    file:write_file(filename:join(PrivDir,".hosts.erlang"),"'"++Hostname++"'.\n"),
88    ok = rpc:call(Node, file, set_cwd, [PrivDir]),
89
90    [PoolNode] = rpc:call(Node, pool, start, [Name]),
91
92    Nodes = rpc:call(Node, pool, get_nodes, []),
93    [rpc:call(N, code, add_patha, [filename:dirname(code:which(?MODULE))]) || N <- Nodes],
94
95    {ok, Node, PoolNode}.
96