-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not return error when closing previous connection on reconnect (
#391)
- Loading branch information
1 parent
a2f81b0
commit 8bfc9cc
Showing
2 changed files
with
33 additions
and
1 deletion.
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
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,32 @@ | ||
//go:build !unit | ||
|
||
package boltz | ||
|
||
import ( | ||
"github.com/BoltzExchange/boltz-client/v2/internal/logger" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestWebsocketReconnect(t *testing.T) { | ||
logger.Init(logger.Options{Level: "debug"}) | ||
api := Api{URL: "http://localhost:9001"} | ||
|
||
ws := api.NewWebsocket() | ||
err := ws.Connect() | ||
require.NoError(t, err) | ||
|
||
firstId := "swapId" | ||
err = ws.Subscribe([]string{firstId}) | ||
require.NoError(t, err) | ||
|
||
firstConn := ws.conn | ||
err = firstConn.Close() | ||
require.NoError(t, err) | ||
|
||
anotherId := "anotherSwapId" | ||
err = ws.Subscribe([]string{anotherId}) | ||
require.NoError(t, err) | ||
require.NotEqual(t, firstConn, ws.conn, "subscribe should reconnect forcefully") | ||
require.Equal(t, []string{firstId, anotherId}, ws.swapIds) | ||
} |