kopia lustrzana https://github.com/bugout-dev/moonstream
Fixed client tests and small changes
rodzic
363388857b
commit
9da72eac44
|
@ -11,6 +11,8 @@ go build -o nodebalancer .
|
||||||
|
|
||||||
## Work with nodebalancer
|
## Work with nodebalancer
|
||||||
|
|
||||||
|
**IMPORTANT** Do not use flag `-debug` in production.
|
||||||
|
|
||||||
### add-access
|
### add-access
|
||||||
|
|
||||||
Add new access for user:
|
Add new access for user:
|
||||||
|
@ -97,3 +99,17 @@ For Web3 providers `access_id` and `data_source` could be specified in headers
|
||||||
--header 'x-node-balancer-data-source: <blockchain/database>'
|
--header 'x-node-balancer-data-source: <blockchain/database>'
|
||||||
--header 'x-node-balancer-access-id: <access_id>'
|
--header 'x-node-balancer-access-id: <access_id>'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
### Running all tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/usr/local/go/bin/go test -run ^*$ github.com/bugout-dev/moonstream/nodes/node_balancer/cmd/nodebalancer -v -count=1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running specified test
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/usr/local/go/bin/go test -run ^TestCleanInactiveClientNodes$ github.com/bugout-dev/moonstream/nodes/node_balancer/cmd/nodebalancer -v -count=1
|
||||||
|
```
|
||||||
|
|
|
@ -206,7 +206,9 @@ func (bpool *BlockchainPool) HealthCheck() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.UpdateNodeState(0, alive)
|
n.UpdateNodeState(0, alive)
|
||||||
log.Printf("Unable to reach node: %s", n.Endpoint.Host)
|
log.Printf("Unable to reach node: %s", n.Endpoint.Host)
|
||||||
resp.Body.Close()
|
if resp != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +216,9 @@ func (bpool *BlockchainPool) HealthCheck() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.UpdateNodeState(0, alive)
|
n.UpdateNodeState(0, alive)
|
||||||
log.Printf("Unable to parse response from %s node, err %v", n.Endpoint.Host, err)
|
log.Printf("Unable to parse response from %s node, err %v", n.Endpoint.Host, err)
|
||||||
resp.Body.Close()
|
if resp.Body != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
|
@ -7,7 +7,20 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func setupSuit(t *testing.T) func(t *testing.T) {
|
||||||
|
t.Log("Setup suit")
|
||||||
|
|
||||||
|
supportedBlockchains = map[string]bool{"ethereum": true}
|
||||||
|
|
||||||
|
return func(t *testing.T) {
|
||||||
|
t.Log("Teardown suit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddClientNode(t *testing.T) {
|
func TestAddClientNode(t *testing.T) {
|
||||||
|
teardownSuit := setupSuit(t)
|
||||||
|
defer teardownSuit(t)
|
||||||
|
|
||||||
var cases = []struct {
|
var cases = []struct {
|
||||||
clients map[string]*Client
|
clients map[string]*Client
|
||||||
expected string
|
expected string
|
||||||
|
@ -16,10 +29,12 @@ func TestAddClientNode(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
CreateClientPools()
|
CreateClientPools()
|
||||||
|
cpool := GetClientPool("ethereum")
|
||||||
|
|
||||||
for id, client := range c.clients {
|
for id, client := range c.clients {
|
||||||
ethereumClientPool.AddClientNode(id, client.Node)
|
cpool.AddClientNode(id, client.Node)
|
||||||
}
|
}
|
||||||
for id := range ethereumClientPool.Client {
|
for id := range cpool.Client {
|
||||||
if id != c.expected {
|
if id != c.expected {
|
||||||
t.Log("Wrong client was added")
|
t.Log("Wrong client was added")
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
|
@ -29,6 +44,9 @@ func TestAddClientNode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetClientNode(t *testing.T) {
|
func TestGetClientNode(t *testing.T) {
|
||||||
|
teardownSuit := setupSuit(t)
|
||||||
|
defer teardownSuit(t)
|
||||||
|
|
||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
|
|
||||||
var cases = []struct {
|
var cases = []struct {
|
||||||
|
@ -39,15 +57,16 @@ func TestGetClientNode(t *testing.T) {
|
||||||
{map[string]*Client{}, "1", nil},
|
{map[string]*Client{}, "1", nil},
|
||||||
{map[string]*Client{"1": {LastCallTs: ts, Node: &Node{Alive: true}}}, "1", &Node{Alive: true}},
|
{map[string]*Client{"1": {LastCallTs: ts, Node: &Node{Alive: true}}}, "1", &Node{Alive: true}},
|
||||||
{map[string]*Client{"2": {LastCallTs: ts, Node: &Node{Alive: true}}}, "1", nil},
|
{map[string]*Client{"2": {LastCallTs: ts, Node: &Node{Alive: true}}}, "1", nil},
|
||||||
{map[string]*Client{"1": {LastCallTs: ts - NB_CLIENT_NODE_KEEP_ALIVE, Node: &Node{Alive: true}}}, "1", nil},
|
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
CreateClientPools()
|
CreateClientPools()
|
||||||
|
cpool := GetClientPool("ethereum")
|
||||||
|
|
||||||
for id, client := range c.clients {
|
for id, client := range c.clients {
|
||||||
ethereumClientPool.Client[id] = client
|
cpool.AddClientNode(id, client.Node)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientNode := ethereumClientPool.GetClientNode(c.id)
|
clientNode := cpool.GetClientNode(c.id)
|
||||||
if !reflect.DeepEqual(clientNode, c.expected) {
|
if !reflect.DeepEqual(clientNode, c.expected) {
|
||||||
t.Log("Wrong node returned")
|
t.Log("Wrong node returned")
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
|
@ -56,6 +75,9 @@ func TestGetClientNode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanInactiveClientNodes(t *testing.T) {
|
func TestCleanInactiveClientNodes(t *testing.T) {
|
||||||
|
teardownSuit := setupSuit(t)
|
||||||
|
defer teardownSuit(t)
|
||||||
|
|
||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
|
|
||||||
var cases = []struct {
|
var cases = []struct {
|
||||||
|
@ -72,12 +94,14 @@ func TestCleanInactiveClientNodes(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
CreateClientPools()
|
CreateClientPools()
|
||||||
|
cpool := GetClientPool("ethereum")
|
||||||
|
|
||||||
for id, client := range c.clients {
|
for id, client := range c.clients {
|
||||||
ethereumClientPool.Client[id] = client
|
cpool.Client[id] = client
|
||||||
}
|
}
|
||||||
|
|
||||||
ethereumClientPool.CleanInactiveClientNodes()
|
cpool.CleanInactiveClientNodes()
|
||||||
for id := range ethereumClientPool.Client {
|
for id := range cpool.Client {
|
||||||
if id != c.expected {
|
if id != c.expected {
|
||||||
t.Log("Wrong client was removed")
|
t.Log("Wrong client was removed")
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
|
|
|
@ -20,7 +20,6 @@ var (
|
||||||
supportedBlockchains map[string]bool
|
supportedBlockchains map[string]bool
|
||||||
|
|
||||||
// Bugout and application configuration
|
// Bugout and application configuration
|
||||||
BUGOUT_AUTH_URL = os.Getenv("BUGOUT_AUTH_URL")
|
|
||||||
BUGOUT_AUTH_CALL_TIMEOUT = time.Second * 5
|
BUGOUT_AUTH_CALL_TIMEOUT = time.Second * 5
|
||||||
NB_APPLICATION_ID = os.Getenv("NB_APPLICATION_ID")
|
NB_APPLICATION_ID = os.Getenv("NB_APPLICATION_ID")
|
||||||
NB_CONTROLLER_TOKEN = os.Getenv("NB_CONTROLLER_TOKEN")
|
NB_CONTROLLER_TOKEN = os.Getenv("NB_CONTROLLER_TOKEN")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Required environment variables for load balancer
|
# Required environment variables for load balancer
|
||||||
export BUGOUT_AUTH_URL="https://auth.bugout.dev"
|
export BUGOUT_BROOD_URL="https://auth.bugout.dev"
|
||||||
export NB_APPLICATION_ID="<application_id_to_controll_access>"
|
export NB_APPLICATION_ID="<application_id_to_controll_access>"
|
||||||
export NB_CONTROLLER_TOKEN="<token_of_controller_user>"
|
export NB_CONTROLLER_TOKEN="<token_of_controller_user>"
|
||||||
export NB_CONTROLLER_ACCESS_ID="<controller_access_id_for_internal_crawlers>"
|
export NB_CONTROLLER_ACCESS_ID="<controller_access_id_for_internal_crawlers>"
|
||||||
|
|
Ładowanie…
Reference in New Issue