mirror of https://github.com/status-im/consul.git
Some fixes
This commit is contained in:
parent
b87f122a5b
commit
9113b26286
|
@ -557,21 +557,20 @@ func (a *Agent) ResumeSync() {
|
||||||
a.state.Resume()
|
a.state.Resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartSendingCoordinate starts a goroutine that periodically sends the local coordinate
|
// SendCoordinates starts a goroutine that periodically sends the local coordinate
|
||||||
// to a server
|
// to a server
|
||||||
func (a *Agent) StartSendingCoordinate() {
|
func (a *Agent) SendCoordinates() {
|
||||||
go func() {
|
|
||||||
var c coordinate.Coordinate
|
var c coordinate.Coordinate
|
||||||
if a.config.Server {
|
if a.config.Server {
|
||||||
c = a.server
|
c = a.server
|
||||||
}
|
}
|
||||||
req := structs.CoordinateUpdateRequest{
|
req := structs.CoordinateUpdateRequest{
|
||||||
|
NodeSpecificRequest: NodeSpecificRequest{
|
||||||
Datacenter: a.config.Datacenter,
|
Datacenter: a.config.Datacenter,
|
||||||
Node: a.config.NodeName,
|
Node: a.config.NodeName,
|
||||||
|
},
|
||||||
QueryOptions: structs.QueryOptions{Token: a.config.ACLToken},
|
QueryOptions: structs.QueryOptions{Token: a.config.ACLToken},
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// persistService saves a service definition to a JSON file in the data dir
|
// persistService saves a service definition to a JSON file in the data dir
|
||||||
|
|
|
@ -4,25 +4,37 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/hashicorp/consul/testutil"
|
"github.com/hashicorp/consul/testutil"
|
||||||
"github.com/hashicorp/serf/coordinate"
|
"github.com/hashicorp/serf/coordinate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// getRandomCoordinate generates a random coordinate.
|
||||||
func getRandomCoordinate() *coordinate.Coordinate {
|
func getRandomCoordinate() *coordinate.Coordinate {
|
||||||
config := coordinate.DefaultConfig()
|
config := coordinate.DefaultConfig()
|
||||||
coord := coordinate.NewCoordinate(config)
|
// Randomly apply updates between n clients
|
||||||
for i := 0; i < len(coord.Vec); i++ {
|
n := 5
|
||||||
coord.Vec[i] = rand.Float64()
|
clients := make([]*coordinate.Client, n)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
clients[i] = coordinate.NewClient(config)
|
||||||
}
|
}
|
||||||
return coord
|
|
||||||
|
for i := 0; i < n*100; i++ {
|
||||||
|
k1 := rand.Intn(n)
|
||||||
|
k2 := rand.Intn(n)
|
||||||
|
if k1 == k2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
clients[k1].Update(clients[k2].GetCoordinate(), time.Duration(rand.Int63())*time.Microsecond)
|
||||||
|
}
|
||||||
|
return clients[rand.Intn(n)].GetCoordinate()
|
||||||
}
|
}
|
||||||
|
|
||||||
func coordinatesEqual(a, b *coordinate.Coordinate) bool {
|
func coordinatesEqual(a, b *coordinate.Coordinate) bool {
|
||||||
config := coordinate.DefaultConfig()
|
config := coordinate.DefaultConfig()
|
||||||
client := coordinate.NewClient(config)
|
dist, err := a.DistanceTo(b, config)
|
||||||
dist, err := client.DistanceBetween(a, b)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue