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 6c729ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions transport/websocketpeer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package transport_test

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/require"

Check failure on line 8 in transport/websocketpeer_test.go

View workflow job for this annotation

GitHub Actions / Check, Lint and Build (ubuntu-latest)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/s-things) --custom-order (gci)

Check failure on line 8 in transport/websocketpeer_test.go

View workflow job for this annotation

GitHub Actions / Check, Lint and Build (macos-latest)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/s-things) --custom-order (gci)

"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"

Check failure on line 13 in transport/websocketpeer_test.go

View workflow job for this annotation

GitHub Actions / Check, Lint and Build (ubuntu-latest)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/s-things) --custom-order (gci)

Check failure on line 13 in transport/websocketpeer_test.go

View workflow job for this annotation

GitHub Actions / Check, Lint and Build (macos-latest)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/s-things) --custom-order (gci)
)

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 6c729ef

Please sign in to comment.