From cc78c18f1d5aab6711af0de342bae283f4160824 Mon Sep 17 00:00:00 2001 From: jackstar12 Date: Thu, 13 Feb 2025 16:02:02 +0100 Subject: [PATCH] fix: dont return error when closing previous connection on reconnect --- pkg/boltz/ws.go | 2 +- pkg/boltz/ws_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 pkg/boltz/ws_test.go diff --git a/pkg/boltz/ws.go b/pkg/boltz/ws.go index de42222e..e9fa854b 100644 --- a/pkg/boltz/ws.go +++ b/pkg/boltz/ws.go @@ -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() } diff --git a/pkg/boltz/ws_test.go b/pkg/boltz/ws_test.go new file mode 100644 index 00000000..af9b600e --- /dev/null +++ b/pkg/boltz/ws_test.go @@ -0,0 +1,30 @@ +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) +}