2012-04-26 31 views
0

我寫一些代碼來測試simple_one_for_one主管,但它不能正常工作,代碼:simple_one_for_one孩子不能啓動

-module(test_simple_one_for_one). 

-behaviour(supervisor). 

%% API 
-export([start_link/0, start_fun_test/0]). 

%% Supervisor callbacks 
-export([init/1]). 

-define(SERVER, ?MODULE). 

%%-------------------------------------------------------------------- 
start_link() -> 
    {ok, Pid} = supervisor:start_link({local, ?SERVER}, ?MODULE, []). 

start_fun_test() -> 
    supervisor:start_child(test_simple_one_for_one, []). 

init([]) -> 
    RestartStrategy = simple_one_for_one, 
    MaxRestarts = 1000, 
    MaxSecondsBetweenRestarts = 3600, 

    SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, 

    Restart = permanent, 
    Shutdown = 2000, 
    Type = worker, 

    AChild = {fun_test_sup, {fun_test, run, []}, 
      Restart, Shutdown, Type, [fun_test]}, 
    io:format("start supervisor------ ~n"), 
    {ok, {SupFlags, [AChild]}}. 

當我運行

test_simple_one_for_one:start_link().

test_simple_one_for_one:start_fun_test(). 

in erl shell,它給我錯誤:

test_simple_one_for_one:start_fun_test(). ** exception exit: {noproc,{gen_server,call, [test_simple_one_for_one,{start_child,[]},infinity]}} in function gen_server:call/3 (gen_server.erl, line 188)

+0

代碼似乎沒問題,並且在start_link和start_fun_test被調用時工作得很好。這個錯誤告訴你在start_link之前運行start_fun_test。 – KrHubert 2012-04-26 12:15:37

回答

1

如果這是您爲測試編寫的所有代碼,請注意,當您註冊一個主管孩子時,您會提供一個{M,F,A}元組,代表您在啓動孩子時調用的函數。

在你的情況下,我認爲它不能簡單地找到fun_test:run/1函數。