From 9591d4c2df694115c5c5ff1b159117fa3032d428 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Fri, 1 Apr 2022 22:35:17 +0200 Subject: Include Websocket StreamRef in gun_down messages --- src/gun_ws.erl | 5 ++--- test/shutdown_SUITE.erl | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gun_ws.erl b/src/gun_ws.erl index e864351..fbd1738 100644 --- a/src/gun_ws.erl +++ b/src/gun_ws.erl @@ -350,6 +350,5 @@ ws_send([Frame|Tail], State, ReplyTo, EvHandler, EvHandlerState0) -> ws_send(Frames, State, _StreamRef, ReplyTo, EvHandler, EvHandlerState) -> ws_send(Frames, State, ReplyTo, EvHandler, EvHandlerState). -%% Websocket has no concept of streams. -down(_) -> - []. +down(#ws_state{stream_ref=StreamRef}) -> + [StreamRef]. diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl index 891aed8..87de32c 100644 --- a/test/shutdown_SUITE.erl +++ b/test/shutdown_SUITE.erl @@ -593,6 +593,7 @@ ws_gun_send_close_frame(Config) -> Frame = {close, 3333, <<>>}, gun:ws_send(ConnPid, StreamRef, Frame), {ws, Frame} = gun:await(ConnPid, StreamRef), + ws_is_down(ConnPid, StreamRef, normal), gun_is_down(ConnPid, ConnRef, normal). ws_gun_receive_close_frame(Config) -> @@ -607,6 +608,7 @@ ws_gun_receive_close_frame(Config) -> {upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef), %% We expect a close frame before the connection is closed. {ws, {close, 3333, <<>>}} = gun:await(ConnPid, StreamRef), + ws_is_down(ConnPid, StreamRef, normal), gun_is_down(ConnPid, ConnRef, normal). closing_gun_shutdown(Config) -> @@ -659,3 +661,11 @@ gun_is_down(ConnPid, ConnRef, Expected) -> Expected = Reason, ok end. + +ws_is_down(ConnPid, StreamRef, Expected) -> + receive + {gun_down, ConnPid, ws, Reason, StreamsDown} -> + Expected = Reason, + [StreamRef] = StreamsDown, + ok + end. -- cgit v1.2.3