@@ -126,6 +126,47 @@ func TestServerStartAcceptConnection(t *testing.T) {
126
126
eventually (t , func () bool { return atomic .LoadInt32 (& connectionCloseCalled ) == 1 })
127
127
}
128
128
129
+ func TestDisconnectHttpConnection (t * testing.T ) {
130
+ // Verify Disconnect() results with Invalid HTTP Connection error
131
+ err := httpConnection {}.Disconnect ()
132
+ assert .Error (t , err )
133
+ assert .Equal (t , ErrInvalidHTTPConnection , err )
134
+ }
135
+
136
+ func TestDisconnectWSConnection (t * testing.T ) {
137
+ connectionCloseCalled := int32 (0 )
138
+ callback := CallbacksStruct {
139
+ OnConnectionCloseFunc : func (conn types.Connection ) {
140
+ atomic .StoreInt32 (& connectionCloseCalled , 1 )
141
+ },
142
+ }
143
+
144
+ // Start a Server.
145
+ settings := & StartSettings {Settings : Settings {Callbacks : callback }}
146
+ srv := startServer (t , settings )
147
+ defer srv .Stop (context .Background ())
148
+
149
+ // Connect to the Server.
150
+ conn , _ , err := dialClient (settings )
151
+
152
+ // Verify that the connection is successful.
153
+ assert .NoError (t , err )
154
+ assert .True (t , atomic .LoadInt32 (& connectionCloseCalled ) == 0 )
155
+
156
+ // Close connection from server side
157
+ srvConn := wsConnection {wsConn : conn }
158
+ err = srvConn .Disconnect ()
159
+ assert .NoError (t , err )
160
+
161
+ // Verify connection disconnected from server side
162
+ eventually (t , func () bool { return atomic .LoadInt32 (& connectionCloseCalled ) == 1 })
163
+ // Waiting for wsConnection to fail ReadMessage() over a Disconnected communication
164
+ eventually (t , func () bool {
165
+ _ , _ , err := conn .ReadMessage ()
166
+ return err != nil
167
+ })
168
+ }
169
+
129
170
func TestServerReceiveSendMessage (t * testing.T ) {
130
171
var rcvMsg atomic.Value
131
172
callbacks := CallbacksStruct {
0 commit comments