agent: add test for consul service sync state

pull/409/head
Ryan Uber 10 years ago
parent 2319460904
commit 525d74aebc

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/hashicorp/consul/consul" "github.com/hashicorp/consul/consul"
"github.com/hashicorp/consul/consul/structs" "github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/consul/testutil"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -326,8 +327,21 @@ func TestAgent_ConsulService(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
defer agent.Shutdown() defer agent.Shutdown()
testutil.WaitForLeader(t, agent.RPC, "dc1")
// Consul service is registered
services := agent.state.Services() services := agent.state.Services()
if _, ok := services[consul.ConsulServiceID]; !ok { if _, ok := services[consul.ConsulServiceID]; !ok {
t.Fatalf("%s service should be registered", consul.ConsulServiceID) t.Fatalf("%s service should be registered", consul.ConsulServiceID)
} }
// Perform anti-entropy on consul service
if err := agent.state.syncService(consul.ConsulServiceID); err != nil {
t.Fatalf("err: %s", err)
}
// Consul service should be in sync
if !agent.state.serviceStatus[consul.ConsulServiceID].inSync {
t.Fatalf("%s service should be in sync", consul.ConsulServiceID)
}
} }

Loading…
Cancel
Save