Skip to content

Commit

Permalink
Add test to close websocket peer
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed Apr 2, 2024
1 parent ea2a2b1 commit 2798a81
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions transport/websocketpeer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package transport_test

import (
"context"
"fmt"
"testing"

"github.com/gammazero/nexus/v3/router"
"github.com/gammazero/nexus/v3/transport"
"github.com/gammazero/nexus/v3/transport/serialize"
"github.com/gammazero/nexus/v3/wamp"
"github.com/stretchr/testify/require"
)

func TestCloseWebsocketPeer(t *testing.T) {
routerConfig := &router.Config{
RealmConfigs: []*router.RealmConfig{
{
URI: wamp.URI("nexus.test.realm"),
},
},
}
r, err := router.NewRouter(routerConfig, nil)
require.NoError(t, err)
defer r.Close()

const wsAddr = "127.0.0.1:8000"
closer, err := router.NewWebsocketServer(r).ListenAndServe(wsAddr)
require.NoError(t, err)
defer closer.Close()

client, err := transport.ConnectWebsocketPeer(
context.Background(), fmt.Sprintf("ws://%s/", wsAddr), serialize.JSON, nil, r.Logger(), nil)
require.NoError(t, err)

// Close the client connection.
client.Close()

// Try closing the client connection again. It should not cause an error.
client.Close()
}

0 comments on commit 2798a81

Please sign in to comment.