state: add tests for services table service and connect indexers

This commit is contained in:
Daniel Nephin 2021-03-26 16:11:03 -04:00
parent 2d2c3e1190
commit 395ebce510
3 changed files with 34 additions and 11 deletions

View File

@ -1368,7 +1368,7 @@ func (s *Store) deleteServiceTxn(tx WriteTxn, idx uint64, nodeName, serviceID st
return fmt.Errorf("failed to clean up mesh-topology associations for %q: %v", name.String(), err) return fmt.Errorf("failed to clean up mesh-topology associations for %q: %v", name.String(), err)
} }
if _, remainingService, err := firstWatchWithTxn(tx, tableServices, "service", svc.ServiceName, entMeta); err == nil { if _, remainingService, err := firstWatchWithTxn(tx, tableServices, indexService, svc.ServiceName, entMeta); err == nil {
if remainingService != nil { if remainingService != nil {
// We have at least one remaining service, update the index // We have at least one remaining service, update the index
if err := catalogUpdateServiceIndexes(tx, svc.ServiceName, idx, entMeta); err != nil { if err := catalogUpdateServiceIndexes(tx, svc.ServiceName, idx, entMeta); err != nil {

View File

@ -168,6 +168,12 @@ func testIndexerTableNodes() map[string]indexerTestCase {
} }
func testIndexerTableServices() map[string]indexerTestCase { func testIndexerTableServices() map[string]indexerTestCase {
obj := &structs.ServiceNode{
Node: "NoDeId",
ServiceID: "SeRviCe",
ServiceName: "ServiceName",
}
return map[string]indexerTestCase{ return map[string]indexerTestCase{
indexID: { indexID: {
read: indexValue{ read: indexValue{
@ -178,10 +184,7 @@ func testIndexerTableServices() map[string]indexerTestCase {
expected: []byte("nodeid\x00service\x00"), expected: []byte("nodeid\x00service\x00"),
}, },
write: indexValue{ write: indexValue{
source: &structs.ServiceNode{ source: obj,
Node: "NoDeId",
ServiceID: "SeRviCe",
},
expected: []byte("nodeid\x00service\x00"), expected: []byte("nodeid\x00service\x00"),
}, },
prefix: []indexValue{ prefix: []indexValue{
@ -202,16 +205,36 @@ func testIndexerTableServices() map[string]indexerTestCase {
indexNode: { indexNode: {
read: indexValue{ read: indexValue{
source: Query{ source: Query{
Value: "NoDe", Value: "NoDeId",
}, },
expected: []byte("node\x00"), expected: []byte("nodeid\x00"),
},
write: indexValue{
source: obj,
expected: []byte("nodeid\x00"),
},
},
indexService: {
read: indexValue{
source: "ServiceName",
expected: []byte("servicename\x00"),
},
write: indexValue{
source: obj,
expected: []byte("servicename\x00"),
},
},
indexConnect: {
read: indexValue{
source: Query{Value: "ConnectName"},
expected: []byte("connectname\x00"),
}, },
write: indexValue{ write: indexValue{
source: &structs.ServiceNode{ source: &structs.ServiceNode{
Node: "NoDe", ServiceName: "ConnectName",
ServiceID: "SeRvIcE", ServiceConnect: structs.ServiceConnect{Native: true},
}, },
expected: []byte("node\x00"), expected: []byte("connectname\x00"),
}, },
}, },
} }

View File

@ -107,7 +107,7 @@ func updateUsage(tx WriteTxn, changes Changes) error {
func updateServiceNameUsage(tx WriteTxn, usageDeltas map[string]int, serviceNameChanges map[structs.ServiceName]int) (map[structs.ServiceName]uniqueServiceState, error) { func updateServiceNameUsage(tx WriteTxn, usageDeltas map[string]int, serviceNameChanges map[structs.ServiceName]int) (map[structs.ServiceName]uniqueServiceState, error) {
serviceStates := make(map[structs.ServiceName]uniqueServiceState, len(serviceNameChanges)) serviceStates := make(map[structs.ServiceName]uniqueServiceState, len(serviceNameChanges))
for svc, delta := range serviceNameChanges { for svc, delta := range serviceNameChanges {
serviceIter, err := getWithTxn(tx, tableServices, "service", svc.Name, &svc.EnterpriseMeta) serviceIter, err := getWithTxn(tx, tableServices, indexService, svc.Name, &svc.EnterpriseMeta)
if err != nil { if err != nil {
return nil, err return nil, err
} }