mirror of
https://github.com/status-im/consul.git
synced 2025-02-18 08:36:46 +00:00
Add a test case
This commit is contained in:
parent
bf5cb7522f
commit
ab9262c656
@ -562,7 +562,7 @@ func (a *Agent) ResumeSync() {
|
|||||||
|
|
||||||
// SendCoordinates starts a loop that periodically sends the local coordinate
|
// SendCoordinates starts a loop that periodically sends the local coordinate
|
||||||
// to a server
|
// to a server
|
||||||
func (a *Agent) SendCoordinates(shutdownCh chan struct{}) {
|
func (a *Agent) SendCoordinates() {
|
||||||
for {
|
for {
|
||||||
intv := aeScale(a.config.SyncCoordinateInterval, len(a.LANMembers()))
|
intv := aeScale(a.config.SyncCoordinateInterval, len(a.LANMembers()))
|
||||||
intv = intv + randomStagger(intv)
|
intv = intv + randomStagger(intv)
|
||||||
@ -587,7 +587,7 @@ func (a *Agent) SendCoordinates(shutdownCh chan struct{}) {
|
|||||||
if err := a.RPC("Coordinate.Update", &req, &reply); err != nil {
|
if err := a.RPC("Coordinate.Update", &req, &reply); err != nil {
|
||||||
a.logger.Printf("[ERR] coordinate update error: %s", err.Error())
|
a.logger.Printf("[ERR] coordinate update error: %s", err.Error())
|
||||||
}
|
}
|
||||||
case <-shutdownCh:
|
case <-a.shutdownCh:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -710,7 +710,7 @@ func (c *Command) Run(args []string) int {
|
|||||||
go c.retryJoinWan(config, errWanCh)
|
go c.retryJoinWan(config, errWanCh)
|
||||||
|
|
||||||
// Start sending network coordinates to servers
|
// Start sending network coordinates to servers
|
||||||
go c.agent.SendCoordinates(c.agent.shutdownCh)
|
go c.agent.SendCoordinates()
|
||||||
|
|
||||||
// Wait for exit
|
// Wait for exit
|
||||||
return c.handleSignals(config, errCh, errWanCh)
|
return c.handleSignals(config, errCh, errWanCh)
|
||||||
|
@ -801,3 +801,40 @@ service "api" {
|
|||||||
policy = "write"
|
policy = "write"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
func TestAgentSendCoordinates(t *testing.T) {
|
||||||
|
conf1 := nextConfig()
|
||||||
|
conf1.SyncCoordinateInterval = 10 * time.Millisecond
|
||||||
|
dir1, agent1 := makeAgent(t, conf1)
|
||||||
|
defer os.RemoveAll(dir1)
|
||||||
|
defer agent1.Shutdown()
|
||||||
|
|
||||||
|
conf2 := nextConfig()
|
||||||
|
conf2.SyncCoordinateInterval = 10 * time.Millisecond
|
||||||
|
dir2, agent2 := makeAgent(t, conf2)
|
||||||
|
defer os.RemoveAll(dir2)
|
||||||
|
defer agent2.Shutdown()
|
||||||
|
|
||||||
|
agent2Addr := fmt.Sprintf("127.0.0.1:%d", agent2.config.Ports.SerfLan)
|
||||||
|
if _, err := agent2.JoinLAN([]string{agent2Addr}); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
testutil.WaitForLeader(t, agent1.RPC, "dc1")
|
||||||
|
|
||||||
|
go agent1.SendCoordinates()
|
||||||
|
go agent2.SendCoordinates()
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
var reply structs.IndexedCoordinate
|
||||||
|
req := structs.CoordinateGetRequest{
|
||||||
|
Datacenter: agent1.config.Datacenter,
|
||||||
|
Node: agent1.config.NodeName,
|
||||||
|
}
|
||||||
|
if err := agent1.RPC("Coordinate.Get", &req, &reply); err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
if reply.Coord == nil {
|
||||||
|
t.Fatalf("should get a coordinate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user