0

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().

erl シェルでは、次のエラーが表示されます。

test_simple_one_for_one:start_fun_test(). ** 例外終了: 関数 gen_server:call/3 の {noproc,{gen_server,call, [test_simple_one_for_one,{start_child,[]},infinity]}} (gen_server.erl、188 行目)

4

1 に答える 1

1

テスト用に記述したコードがすべてである場合は、スーパーバイザーの子を登録するときに、子を開始するときに呼び出される関数を表す {M, F, A} タプルを提供することに注意してください。

あなたの場合、単純に fun_test:run/1 関数を見つけることはできないと思います。

于 2012-04-26T19:49:48.877 に答える