2017-07-22 22 views
1

我有一個測試模塊,用於測試我的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}

我想知道是,我應該尋找什麼樣的代碼,這將導致我的董事會得到停止的原因?

完整的源是在這裏:[email protected]:QuantumProductions/tunnel.git

編輯:董事會包括本

handle_call(stop, _From, State) -> 
    {stop, normal, shutdown_ok, State}; 
handle_call(_, _, Board) -> 
    {reply, {error, unrecognized, Board}, Board}. 

編輯:我最好的猜測是eunit內創建自動終止其進程測試?

回答

0

爲什麼borad最後一條消息是[]?根據您使用的代碼gen_server:stop/1調用gen:stop/1,調用gen:stop/3,調用proc_lib:stop/3,最終調用sys:terminate/3。當您爲gen_server調用sys:terminate/3時,sys調用gen_server:system_terminate/4,它將gen_server:terminate/6[]作爲最後的消息!

爲什麼borad以原因終止{terminated, ...}?根據io代碼,io:format/2最後調用io:execute_request/2,並且您得到this,因爲io進程已終止,並且在here中它變爲{terminated, ...}

+0

那麼我該如何終止我的過程沒有錯誤? – quantumpotato

+0

我想你在Eunit測試中丟失了io進程,我推薦使用標準的sys調試,而不是io:格式。 http://erlang.org/doc/design_principles/spec_proc.html#debug – Pouriya

+0

那麼,Eunit是否會告訴程序終止?當你說「失落的過程」 - 你的意思是Eunit殺死了它? – quantumpotato