generated from KyberNetwork/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Retry and ACK for Broadcast Flow (#117)
* add retry and ack for broadcast flow * fix lint * update unit test * update unit test
- Loading branch information
1 parent
8e66fce
commit cbe2545
Showing
4 changed files
with
117 additions
and
30 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,59 @@ | ||
package server | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/KyberNetwork/tradinglib/pkg/httpsign" | ||
"github.com/gorilla/websocket" | ||
) | ||
|
||
func TestSubscribe(t *testing.T) { | ||
t.Skip("set env to run test") | ||
wsURL := os.Getenv("URL") // Replace with actual WebSocket URL | ||
key := os.Getenv("KEY") | ||
secret := os.Getenv("SECRET") | ||
|
||
request, err := http.NewRequest(http.MethodGet, wsURL+"?id=cscv9ubrk77vgbjftu5g", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, err = httpsign.Sign(request, key, []byte(secret)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// local test | ||
// request, err := http.NewRequest("GET", "ws://localhost:8082/eventlogws", nil) | ||
// wsURL := "ws://localhost:8082/eventlogws" | ||
|
||
// Establish a connection with the WebSocket server | ||
conn, _, err := websocket.DefaultDialer.Dial(wsURL+"?id=cscv9ubrk77vgbjftu5g", request.Header) | ||
if err != nil { | ||
t.Fatal("Error connecting to WebSocket server:", err) | ||
} | ||
defer conn.Close() | ||
|
||
go func() { | ||
ticker := time.NewTicker(time.Minute) | ||
defer ticker.Stop() | ||
for ; ; <-ticker.C { | ||
if err = conn.WriteMessage(websocket.PingMessage, nil); err != nil { | ||
log.Println("Ping error:", err) | ||
return | ||
} | ||
} | ||
}() | ||
|
||
for { | ||
// cscv9ubrk77vgbjftu5g | ||
_, message, err := conn.ReadMessage() | ||
if err != nil { | ||
t.Fatal("Error reading from websocket:", err) | ||
} | ||
log.Printf("Received: %s", message) | ||
} | ||
} |
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
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