-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
wpool_worker_SUITE.erl
100 lines (82 loc) · 2.57 KB
/
wpool_worker_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% This file is licensed to you under the Apache License,
% Version 2.0 (the "License"); you may not use this file
% except in compliance with the License. You may obtain
% a copy of the License at
%
% https://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing,
% software distributed under the License is distributed on an
% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
% KIND, either express or implied. See the License for the
% specific language governing permissions and limitations
% under the License.
%% @hidden
-module(wpool_worker_SUITE).
-behaviour(ct_suite).
-type config() :: [{atom(), term()}].
-export_type([config/0]).
-export([all/0]).
-export([init_per_suite/1, end_per_suite/1]).
-export([call/1, cast/1, complete_coverage/1]).
-export([ok/0, error/0]).
-spec all() -> [atom()].
all() ->
[Fun
|| {Fun, 1} <- module_info(exports),
not lists:member(Fun, [init_per_suite, end_per_suite, module_info])].
-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
ok = wpool:start(),
Config.
-spec end_per_suite(config()) -> config().
end_per_suite(Config) ->
wpool:stop(),
Config.
-spec ok() -> ?MODULE.
ok() ->
?MODULE.
-spec error() -> no_return().
error() ->
exit(?MODULE).
-spec call(config()) -> {comment, []}.
call(_Config) ->
start_pool(),
?MODULE = wpool_worker:call(?MODULE, ?MODULE, ok, []),
try wpool_worker:call(?MODULE, ?MODULE, error, []) of
R ->
no_result = R
catch
exit:?MODULE ->
ok
end,
{error, invalid_request} = wpool:call(?MODULE, error),
ok = wpool:stop_sup_pool(?MODULE),
{comment, []}.
-spec cast(config()) -> {comment, []}.
cast(_Config) ->
start_pool(),
ok = wpool_worker:cast(?MODULE, ?MODULE, ok, []),
ok = wpool_worker:cast(?MODULE, ?MODULE, error, []),
ok = wpool:cast(?MODULE, x),
ok = wpool_worker:cast(?MODULE, erlang, send, [self(), {a, message}]),
receive
{a, message} ->
ok
after 1000 ->
ct:fail("Timeout while waiting for cast response")
end,
ok = wpool:stop_sup_pool(?MODULE),
{comment, []}.
-spec complete_coverage(config()) -> {comment, []}.
complete_coverage(_Config) ->
start_pool(),
{ok, AWorker} = wpool:call(?MODULE, {erlang, self, []}),
true = is_process_alive(AWorker),
AWorker ! info,
true = is_process_alive(AWorker),
{comment, []}.
start_pool() ->
{ok, _Pid} =
wpool:start_sup_pool(?MODULE, [{workers, 1}, {worker, {wpool_worker, undefined}}]),
started.