-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
crashy_server.erl
64 lines (53 loc) · 1.9 KB
/
crashy_server.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
% 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.
%% @doc a gen_server built to test wpool_process
-module(crashy_server).
-behaviour(gen_server).
%% gen_server callbacks
-export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2,
handle_info/2]).
-dialyzer([no_behaviours]).
-type from() :: {pid(), reference()}.
-export_type([from/0]).
%%%===================================================================
%%% callbacks
%%%===================================================================
-spec init(Something) -> {ok, Something}.
init(Something) ->
{ok, Something}.
-spec terminate(Any, term()) -> Any.
terminate(Reason, _State) ->
Reason.
-spec code_change(string(), State, any()) -> {ok, State}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-spec handle_info(timeout | Info, term()) -> {noreply, timeout} | Info.
handle_info(timeout, _State) ->
{noreply, timeout};
handle_info(undef, _State) ->
erlang:error(undef);
handle_info(Info, _State) ->
Info.
-spec handle_cast(Cast, term()) -> Cast.
handle_cast(crash, _State) ->
error(crash_requested);
handle_cast(Cast, _State) ->
Cast.
-spec handle_call(state | Call, from(), State) -> {reply, State, State} | Call.
handle_call(state, _From, State) ->
{reply, State, State};
handle_call(crash, _From, _State) ->
error(crash_requested);
handle_call(Call, _From, State) ->
{reply, Call, State}.