Commits

Fred T-H committed 2bd9a7c

Made the client aware of a dying user.

The client:listen/2 function now propagates the exit signal from the
usr if said signal is anything but 'normal'. As of now, no default
behavior is chosen when the user dies, so let a supervisor handle this.

  • Participants
  • Parent commits cfbc759

Comments (0)

Files changed (2)

 %% picks messages belonging to Id
 listen(Id, HandlerId) ->
     receive
-        {{Id, HandlerId}, Msg} -> [Msg | listen1(Id, HandlerId)]
+        {{Id, HandlerId}, Msg} -> [Msg | listen1(Id, HandlerId)];
+        {gen_event_EXIT, HandlerId, Reason} ->
+            case Reason of
+                normal -> ok;
+                Reason -> exit(Reason)
+            end
     after ?LISTEN_TIMEOUT ->
         []
     end.

src/usr_SUITE.erl

 %%--------------------------------------------------------------------
 all() -> 
     [usr_timeout, usr_subscribe, usr_message, usr_relay, usr_conv,
-     client_conv, two_clients_one_usr].
+     client_conv, two_clients_one_usr, client_aware_crashed_user].
 %%--------------------------------------------------------------------
 %% Function: TestCase(Config0) ->
 %%               ok | exit() | {skip,Reason} | {comment,Comment} |
     [{sent, A, "hi"},{received, A, "hi"}] = client:listen(A,ConnB),
     client:disconnect(A,ConnA),
     client:disconnect(A,ConnB).
+
+client_aware_crashed_user(_Config) ->
+    process_flag(trap_exit, true), % not actually needed?
+    A = make_ref(),
+    {ok, H} = client:connect(A),
+    usr:terminate(A,kill),
+    try client:listen(A,H) of
+        _ -> throw(no_dead_signal)
+    catch
+        exit:Reason -> Reason
+    end.