Speed up test by registering services concurrently (#16509)

This commit is contained in:
Chris S. Kim 2023-03-02 14:36:44 -05:00 committed by GitHub
parent 7d4c7efe0a
commit fea543993d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 13 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/coordinate"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"github.com/hashicorp/consul/agent/config" "github.com/hashicorp/consul/agent/config"
"github.com/hashicorp/consul/agent/consul" "github.com/hashicorp/consul/agent/consul"
@ -4883,21 +4884,26 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
services := []string{"normal", "truncated"} services := []string{"normal", "truncated"}
for index, service := range services { for index, service := range services {
numServices := (index * 5000) + 2 numServices := (index * 5000) + 2
var eg errgroup.Group
for i := 1; i < numServices; i++ { for i := 1; i < numServices; i++ {
args := &structs.RegisterRequest{ j := i
Datacenter: "dc1", eg.Go(func() error {
Node: fmt.Sprintf("%s-%d.acme.com", service, i), args := &structs.RegisterRequest{
Address: fmt.Sprintf("127.%d.%d.%d", 0, (i / 255), i%255), Datacenter: "dc1",
Service: &structs.NodeService{ Node: fmt.Sprintf("%s-%d.acme.com", service, j),
Service: service, Address: fmt.Sprintf("127.%d.%d.%d", 0, (j / 255), j%255),
Port: 8000, Service: &structs.NodeService{
}, Service: service,
} Port: 8000,
},
}
var out struct{} var out struct{}
if err := a.RPC(context.Background(), "Catalog.Register", args, &out); err != nil { return a.RPC(context.Background(), "Catalog.Register", args, &out)
t.Fatalf("err: %v", err) })
} }
if err := eg.Wait(); err != nil {
t.Fatalf("error registering: %v", err)
} }
// Register an equivalent prepared query. // Register an equivalent prepared query.