-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea2a2b1
commit 6c729ef
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Check, Lint and Build (ubuntu-latest)
|
||
|
||
"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 GitHub Actions / Check, Lint and Build (ubuntu-latest)
|
||
) | ||
|
||
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() | ||
} |