anchor.diff:      end),
       Config;
   
  +init_per_testcase(event_stream_crash_test, Config) ->
  +    [Worker | _] = ?config(op_worker_nodes, Config),
  +    Self = self(),
  +    SessId = <<"session_id">>,
  +    Cred = #credentials{user_id = <<"user_id">>},
  +    test_utils:mock_new(Worker, [communicator, logger]),
  +    test_utils:mock_expect(Worker, communicator, send, fun
  +        (_, _) -> ok
  +    end),
  +    test_utils:mock_expect(Worker, logger, dispatch_log, fun
  +        (_, _, _, [_, _, kill], _) -> meck:exception(throw, crash);
  +        (A, B, C, D, E) -> meck:passthrough([A, B, C, D, E])
  +    end),
  +    session_setup(Worker, SessId, Cred, Self),
  +    [{session_id, SessId} | Config];
  +
   init_per_testcase(event_manager_test, Config) ->
       [Worker | _] = ?config(op_worker_nodes, Config),
       Self = self(),
  
positive.code:     test_utils:mock_validate(Workers, communicator),
      test_utils:mock_unload(Workers, communicator),
      Config;
  
  end_per_testcase(event_manager_test, Config) ->
      [Worker | _] = ?config(op_worker_nodes, Config),
  
negative.code: 
      session_teardown(Worker1, SessId2),
      session_teardown(Worker2, SessId1),
  
      ok.
  
  event_stream_crash_test(Config) ->
      [Worker | _] = ?config(op_worker_nodes, Config),
      SessId = ?config(session_id, Config),
      Self = self(),
      EvtsCount = 100,
      HalfEvts = round(EvtsCount / 2),
  
      {ok, SubId} = subscribe(Worker,
          gui,
          fun(#write_event{}) -> true; (_) -> false end,
          fun(Meta) -> Meta >= EvtsCount end,
          [fun(Evts) -> Self ! {handler, Evts} end]
      ),
  
      % Emit first part of events.
      lists:foreach(fun(N) ->
          emit(Worker, #write_event{size = 1, counter = 1, file_size = N + 1,
              blocks = [#file_block{offset = N, size = 1}]}, SessId)
      end, lists:seq(0, HalfEvts - 1)),
  
      % Get event stream pid.
      {ok, {SessSup, _}} = rpc:call(Worker, session,
          get_session_supervisor_and_node, [SessId]),
      {ok, EvtManSup} = get_child(SessSup, event_manager_sup),
      {ok, EvtStmSup} = get_child(EvtManSup, event_stream_sup),
      {ok, EvtStm} = get_child(EvtStmSup, undefined),
  
      % Send crash message and wait for event stream recovery.
      gen_server:cast(EvtStm, kill),
      timer:sleep(?TIMEOUT),
  
      % Emit second part of events.
      lists:foreach(fun(N) ->
          emit(Worker, #write_event{size = 1, counter = 1, file_size = N + 1,
              blocks = [#file_block{offset = N, size = 1}]}, SessId)
      end, lists:seq(HalfEvts, EvtsCount - 1)),
  
      % Check whether event handlers have been executed.
      ?assertMatch({ok, _}, test_utils:receive_msg({handler, [#write_event{
          size = EvtsCount, counter = EvtsCount, file_size = EvtsCount,
          blocks = [#file_block{offset = 0, size = EvtsCount}]}]}, ?TIMEOUT)),
      ?assertEqual({error, timeout}, test_utils:receive_any()),
  
      unsubscribe(Worker, SubId),
  
      ok.
  
  