Different fake nodes for test

pull/755/head
kompotkot 2023-01-25 13:36:17 +00:00
rodzic 3228e631cb
commit 3c63297825
3 zmienionych plików z 20 dodań i 9 usunięć

Wyświetl plik

@ -153,5 +153,5 @@ go build -o fakenode tests/fake_node/main.go
```
```bash
TEST_API_URL="http://127.0.0.1:8545/nb/test/jsonrpc" /usr/local/go/bin/go test -run ^TestHealthCheck$ github.com/bugout-dev/moonstream/nodes/node_balancer/cmd/nodebalancer -v -count=1
TEST_API_URL="http://127.0.0.1:8545/nb" /usr/local/go/bin/go test -run ^TestHealthCheck$ github.com/bugout-dev/moonstream/nodes/node_balancer/cmd/nodebalancer -v -count=1
```

Wyświetl plik

@ -2,6 +2,7 @@ package main
import (
"bytes"
"fmt"
"net/http"
"net/url"
"os"
@ -14,13 +15,20 @@ var testApiUrl = os.Getenv("TEST_API_URL")
func setupBalancerSuit(t *testing.T) func(t *testing.T) {
t.Log("Setup Balancer suit")
testEndpoint, err := url.Parse(testApiUrl)
testEndpoint1, err := url.Parse(fmt.Sprintf("%s/test1/jsonrpc", testApiUrl))
if err != nil {
t.Error(err)
}
testEndpoint2, err := url.Parse(fmt.Sprintf("%s/test2/jsonrpc", testApiUrl))
if err != nil {
t.Error(err)
}
testNode := &Node{
Endpoint: testEndpoint,
testNode1 := &Node{
Endpoint: testEndpoint1,
}
testNode2 := &Node{
Endpoint: testEndpoint2,
}
testBlockchainPools := make(map[string]*NodePool)
@ -28,13 +36,13 @@ func setupBalancerSuit(t *testing.T) func(t *testing.T) {
NodesMap: make(map[string][]*Node),
}
testBlockchainPools["test"].NodesMap["tag_1"] = append(
testBlockchainPools["test"].NodesMap["tag_1"], testNode,
testBlockchainPools["test"].NodesMap["tag_1"], testNode1,
)
testBlockchainPools["test"].NodesMap["tag_2"] = append(
testBlockchainPools["test"].NodesMap["tag_2"], testNode,
testBlockchainPools["test"].NodesMap["tag_2"], testNode2,
)
testBlockchainPools["test"].NodesSet = append(
testBlockchainPools["test"].NodesSet, testNode,
testBlockchainPools["test"].NodesSet, testNode1, testNode2,
)
blockchainPools = make(map[string]*NodePool)

Wyświetl plik

@ -6,7 +6,9 @@ import (
"fmt"
"log"
"net/http"
"math/rand"
"time"
"strconv"
)
type PingResponse struct {
@ -30,7 +32,7 @@ func pingRoute(w http.ResponseWriter, r *http.Request) {
func lbRoute(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
res := NodeStatusResponse{NodeStatusResultResponse{Number: "11"}}
res := NodeStatusResponse{NodeStatusResultResponse{Number: strconv.Itoa(rand.Intn(100))}}
json.NewEncoder(w).Encode(res)
}
@ -64,7 +66,8 @@ func main() {
commonMux := http.NewServeMux()
commonMux.HandleFunc("/ping", pingRoute)
commonMux.HandleFunc("/nb/test/jsonrpc", lbRoute)
commonMux.HandleFunc("/nb/test1/jsonrpc", lbRoute)
commonMux.HandleFunc("/nb/test2/jsonrpc", lbRoute)
commonHandler := logMiddleware(commonMux)
commonHandler = panicMiddleware(commonHandler)