我有一个测试我的Table
模块的测试模块。
我的Table
模块在终止时会调用:
terminate(_, State = {Board, Status, Players}) ->
gen_server:stop(Board),
...stopping other processes,
io:format("Table Terminating.~p~n", [State]),
ok.
这是我的代码中唯一会阻止Board
进程的部分。
运行我的测试后,我会在大约一分钟后得到这个:
=ERROR REPORT==== 21-Jul-2017::22:28:40 ===
** Generic server <0.92.0> terminating
** Last message in was []
** When Server state == [[{spawn,x,none},
{recent,x,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none},
{spawn,o,none}]]
** Reason for termination ==
** {terminated,[{io,format,
[<0.90.0>,"Board.~p~n",
[[[{spawn,x,none},
{recent,x,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none},
{spawn,o,none}]]]],
[]},
{board,terminate,2,[{file,"board.erl"},{line,319}]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,629}]},
{gen_server,terminate,7,[{file,"gen_server.erl"},{line,795}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]
看起来像Board
模块不正确地终止。 Board
终止是这样的:
terminate(normal, State) ->
io:format("Board.~p~n", [State]),
ok.
我尝试在独立模块b
中重现这一点:
-module(b).
-compile(export_all).
init([]) -> {ok, {1, 2}}.
terminate(_, State) ->
io:format("Table Terminating.~p~n", [State]),
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
handle_cast(_, State) ->
{noreply, State}.
handle_info(Msg, State) ->
io:format("Unexpected message: ~p~n",[Msg]),
{noreply, State}.
go() ->
gen_server:start_link(?MODULE, [], []).
未成功:
4> {ok, B} = b:go().
{ok,<0.74.0>}
5> gen_server:stop(B).
Table Terminating.{1,2}
我想知道的是,我应该寻找什么样的代码才能让我的理事会得到** Reason for termination ==
** {terminated
理由停止?
完整来源是:git@github.com:QuantumProductions / tunnel.git
编辑:董事会包括此
handle_call(stop, _From, State) ->
{stop, normal, shutdown_ok, State};
handle_call(_, _, Board) ->
{reply, {error, unrecognized, Board}, Board}.
编辑:我最好的猜测是eunit
是在其测试中自动终止的进程吗?
答案 0 :(得分:0)
为什么borad
上一封邮件是[]
?根据您使用gen_server:stop/1
调用gen:stop/1
调用gen:stop/3
调用sys:terminate/3
调用proc_lib:stop/3
调用最终调用sys:terminate/3
的代码。当您为gen_server调用[]
时,sys会调用gen_server:system_terminate/4
,并以borad
作为最后一条消息调用gen_server:terminate/6
!
为什么{terminated, ...}
因理由io
而终止?根据{{1}}代码,io:format/2
最终调用了io:execute_request/2
,您获得了this
,因为io流程已终止,而here则变为{terminated, ...}
。< / p>