Skip to content

Commit

Permalink
fix: do not return error when closing previous connection on reconnect (
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 authored Feb 13, 2025
1 parent 4bba474 commit 094d4a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/boltz/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (boltz *Websocket) Reconnect() error {
logger.Infof("Force reconnecting to Boltz ws")
boltz.reconnect = true
if err := boltz.conn.Close(); err != nil {
return fmt.Errorf("could not close boltz ws: %w", err)
logger.Warnf("could not close boltz ws: %v", err)
}
return boltz.Connect()
}
32 changes: 32 additions & 0 deletions pkg/boltz/ws_test.go
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)
}

0 comments on commit 094d4a6

Please sign in to comment.