Revert "local state: refactor TestAgentAntiEntropy_EnableTagOverride"

This reverts commit c28e23eac8.
This commit is contained in:
Frank Schroeder 2017-10-23 10:08:33 +02:00
parent 46641e44d9
commit 9fdea75d99
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
1 changed files with 54 additions and 64 deletions

View File

@ -237,7 +237,7 @@ func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
} }
var out struct{} var out struct{}
// register a local service with tag override enabled // EnableTagOverride = true
srv1 := &structs.NodeService{ srv1 := &structs.NodeService{
ID: "svc_id1", ID: "svc_id1",
Service: "svc1", Service: "svc1",
@ -246,8 +246,19 @@ func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
EnableTagOverride: true, EnableTagOverride: true,
} }
a.State.AddService(srv1, "") a.State.AddService(srv1, "")
if err := a.State.SyncChanges(); err != nil {
t.Fatalf("err: %v", err)
}
srv1_mod := new(structs.NodeService)
*srv1_mod = *srv1
srv1_mod.Port = 7100
srv1_mod.Tags = []string{"tag1_mod"}
args.Service = srv1_mod
if err := a.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err)
}
// register a local service with tag override disabled // EnableTagOverride = false
srv2 := &structs.NodeService{ srv2 := &structs.NodeService{
ID: "svc_id2", ID: "svc_id2",
Service: "svc2", Service: "svc2",
@ -256,38 +267,15 @@ func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
EnableTagOverride: false, EnableTagOverride: false,
} }
a.State.AddService(srv2, "") a.State.AddService(srv2, "")
srv2_mod := new(structs.NodeService)
// make sure they are both in the catalog *srv2_mod = *srv2
if err := a.State.SyncChanges(); err != nil { srv2_mod.Port = 7200
t.Fatalf("err: %v", err) srv2_mod.Tags = []string{"tag2_mod"}
} args.Service = srv2_mod
// update the services in the catalog and change the tags and port.
// Only tag changes should be propagated for services where tag
// override is enabled.
args.Service = &structs.NodeService{
ID: srv1.ID,
Service: srv1.Service,
Tags: []string{"tag1_mod"},
Port: 7100,
EnableTagOverride: true,
}
if err := a.RPC("Catalog.Register", args, &out); err != nil { if err := a.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
args.Service = &structs.NodeService{
ID: srv2.ID,
Service: srv2.Service,
Tags: []string{"tag2_mod"},
Port: 7200,
EnableTagOverride: false,
}
if err := a.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err)
}
// sync catalog and local state
if err := a.State.SyncFull(); err != nil { if err := a.State.SyncFull(); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
@ -298,42 +286,44 @@ func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
} }
var services structs.IndexedNodeServices var services structs.IndexedNodeServices
retry.Run(t, func(r *retry.R) {
// runtime.Gosched()
if err := a.RPC("Catalog.NodeServices", &req, &services); err != nil { if err := a.RPC("Catalog.NodeServices", &req, &services); err != nil {
t.Fatalf("err: %v", err) r.Fatalf("err: %v", err)
} }
a.State.RLock()
defer a.State.RUnlock()
// All the services should match // All the services should match
for id, serv := range services.NodeServices.Services { for id, serv := range services.NodeServices.Services {
serv.CreateIndex, serv.ModifyIndex = 0, 0 serv.CreateIndex, serv.ModifyIndex = 0, 0
switch id { switch id {
case "svc_id1": case "svc_id1":
// tags should be modified but not the port if serv.ID != "svc_id1" ||
got := serv serv.Service != "svc1" ||
want := &structs.NodeService{ serv.Port != 6100 ||
ID: "svc_id1", !reflect.DeepEqual(serv.Tags, []string{"tag1_mod"}) {
Service: "svc1", r.Fatalf("bad: %v %v", serv, srv1)
Tags: []string{"tag1_mod"},
Port: 6100,
EnableTagOverride: true,
}
if !verify.Values(t, "", got, want) {
t.FailNow()
} }
case "svc_id2": case "svc_id2":
got, want := serv, srv2 if serv.ID != "svc_id2" ||
if !verify.Values(t, "", got, want) { serv.Service != "svc2" ||
t.FailNow() serv.Port != 6200 ||
!reflect.DeepEqual(serv.Tags, []string{"tag2"}) {
r.Fatalf("bad: %v %v", serv, srv2)
} }
case structs.ConsulServiceID: case structs.ConsulServiceID:
// ignore // ignore
default: default:
t.Fatalf("unexpected service: %v", id) r.Fatalf("unexpected service: %v", id)
} }
} }
if err := servicesInSync(a.State, 2); err != nil { if err := servicesInSync(a.State, 2); err != nil {
t.Fatal(err) r.Fatal(err)
} }
})
} }
func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) {