HG-534: Fix 'unknown message error' in event handler (#130)

* HG-534: Fix 'unknown message error' in event handler

* Revert "HG-534: Fix 'unknown message error' in event handler"

This reverts commit efd6c51129adeca1369296f360f3e931732f5c76.

* HG-534: Fix unknown message error

* More accurate test

* Fix lint error
This commit is contained in:
Sergey Yelin 2020-02-14 21:56:29 +03:00 committed by GitHub
parent ed644d7d70
commit d55dbf551a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -59,13 +59,23 @@ info(StreamID, Info, #{next := Next0} = State) ->
terminate( terminate(
StreamID, StreamID,
{socket_error, _, HumanReadable} = Reason, {socket_error, _, HumanReadable} = Reason,
#{woody_state := WoodyState, next := Next, event_to_emit:= Event} #{woody_state := WoodyState, next := Next, event_to_emit := Event = ?EV_SERVER_RECEIVE}
) -> ) ->
woody_event_handler:handle_event(Event, woody_event_handler:handle_event(Event,
WoodyState, WoodyState,
#{status => error, reason => woody_util:to_binary(HumanReadable)} #{status => error, reason => woody_util:to_binary(HumanReadable)}
), ),
cowboy_stream:terminate(StreamID, Reason, Next); cowboy_stream:terminate(StreamID, Reason, Next);
terminate(
StreamID,
{socket_error, _, HumanReadable} = Reason,
#{woody_state := WoodyState, next := Next, event_to_emit := Event = ?EV_SERVICE_HANDLER_RESULT}
) ->
woody_event_handler:handle_event(Event,
WoodyState,
#{status => error, class => system, result => woody_util:to_binary(HumanReadable)}
),
cowboy_stream:terminate(StreamID, Reason, Next);
terminate(StreamID, Reason, #{next := Next}) -> terminate(StreamID, Reason, #{next := Next}) ->
cowboy_stream:terminate(StreamID, Reason, Next). cowboy_stream:terminate(StreamID, Reason, Next).

View File

@ -65,12 +65,15 @@ init(_) ->
-spec handle_call({event(), rpc_id(), event_meta(), options()}, _, state()) -> -spec handle_call({event(), rpc_id(), event_meta(), options()}, _, state()) ->
{reply, ok | {ok, pos_integer()}, state()}. {reply, ok | {ok, pos_integer()}, state()}.
handle_call({Event, Rpc, #{status := error, reason := ?SOCKET_CLOSED} = Meta, Opts}, _, #{ handle_call({Event = ?EV_SERVICE_HANDLER_RESULT, Rpc,
#{status := error, class := system, result := ?SOCKET_CLOSED} = Meta, Opts}, _, #{
socket_errors_caught := Caught socket_errors_caught := Caught
} = State) when } = State) ->
Event =:= ?EV_SERVICE_HANDLER_RESULT orelse woody_tests_SUITE:handle_event(Event, Rpc, Meta, Opts),
Event =:= ?EV_SERVER_RECEIVE {reply, ok, State#{socket_errors_caught => Caught + 1}};
-> handle_call({Event = ?EV_SERVER_RECEIVE, Rpc, #{status := error, reason := ?SOCKET_CLOSED} = Meta, Opts}, _, #{
socket_errors_caught := Caught
} = State) ->
woody_tests_SUITE:handle_event(Event, Rpc, Meta, Opts), woody_tests_SUITE:handle_event(Event, Rpc, Meta, Opts),
{reply, ok, State#{socket_errors_caught => Caught + 1}}; {reply, ok, State#{socket_errors_caught => Caught + 1}};