Skip to content

Commit

Permalink
Wait for instance startup; use random routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmaen committed Jan 28, 2025
1 parent e2a913d commit 2474f7a
Show file tree
Hide file tree
Showing 25 changed files with 1,477 additions and 11 deletions.
4 changes: 2 additions & 2 deletions assets/dora/man_route_opt_lb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
applications:
- name: ((name))
routes:
- route: dora-rr.((domain))
- route: ((roundrobinhost)).((domain))
options:
loadbalancing: round-robin
- route: dora-lc.((domain))
- route: ((leastconnhost)).((domain))
options:
loadbalancing: least-connections
processes:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/cloudfoundry/cf-test-helpers/v2 v2.10.0
github.com/cloudfoundry/noaa/v2 v2.5.0
github.com/cloudfoundry/sonde-go v0.0.0-20230710164515-a0a43d1dbbf8
github.com/google/uuid v1.6.0
github.com/mholt/archiver/v3 v3.5.1
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
Expand Down
33 changes: 24 additions & 9 deletions routing/per_route_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,50 @@ import (
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
"github.com/cloudfoundry/cf-test-helpers/v2/helpers"

"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = RoutingDescribe("Per-Route Options", func() {
var (
appName string
appId string
instanceIds [2]string
appName string
appId string
instanceIds [2]string
leastConnHost string
roundRobinHost string
)

Context("when an app sets the loadbalancing algorithm", func() {
BeforeEach(func() {
appName = random_name.CATSRandomName("APP")
asset := assets.NewAssets()
leastConnHost = "dora-lc-" + uuid.NewString()
roundRobinHost = "dora-rr-" + uuid.NewString()
Expect(cf.Cf("push",
appName,
"-b", Config.GetRubyBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", asset.Dora,
"--var", fmt.Sprintf("domain=%s", Config.GetAppsDomain()),
"--var", fmt.Sprintf("name=%s", appName),
"--var", fmt.Sprintf("leastconnhost=%s", leastConnHost),
"--var", fmt.Sprintf("roundrobinhost=%s", roundRobinHost),
"-f", filepath.Join(asset.Dora, "man_route_opt_lb.yml"),
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
appId = app_helpers.GetAppGuid(appName)

instanceIds[0] = helpers.CurlApp(Config, appName, "/id", "-H", fmt.Sprintf("X-Cf-App-Instance: %s:0", appId))
instanceIds[1] = helpers.CurlApp(Config, appName, "/id", "-H", fmt.Sprintf("X-Cf-App-Instance: %s:1", appId))
for i := range 2 {
for {
id := helpers.CurlApp(Config, appName, "/id", "-H", fmt.Sprintf("X-Cf-App-Instance: %s:%d", appId, i))
if err := uuid.Validate(id); err == nil {
instanceIds[i] = id
break
}
time.Sleep(1 * time.Second)
}
}
})

AfterEach(func() {
Expand All @@ -51,7 +66,7 @@ var _ = RoutingDescribe("Per-Route Options", func() {

Context("when it's set to round-robin", func() {
It("distributes requests evenly", func() {
doraUrl := fmt.Sprintf("%sdora-rr.%s", Config.Protocol(), Config.GetAppsDomain())
doraUrl := fmt.Sprintf("%s%s.%s", Config.Protocol(), roundRobinHost, Config.GetAppsDomain())

for i := 0; i < 10; i++ {
go func() {
Expand All @@ -76,7 +91,7 @@ var _ = RoutingDescribe("Per-Route Options", func() {

Context("when it's set to least-connection", func() {
It("always sends the request to the instance with less active connections", func() {
doraUrl := fmt.Sprintf("%sdora-lc.%s", Config.Protocol(), Config.GetAppsDomain())
doraUrl := fmt.Sprintf("%s%s.%s", Config.Protocol(), leastConnHost, Config.GetAppsDomain())

for i := 0; i < 10; i++ {
go func() {
Expand All @@ -94,8 +109,8 @@ var _ = RoutingDescribe("Per-Route Options", func() {
}

// allow for some wiggle-room
Expect(reqCount[0]).To(BeNumerically("<=", 3))
Expect(reqCount[1]).To(BeNumerically(">=", 17))
Expect(reqCount[0]).To(BeNumerically("<=", 5))
Expect(reqCount[1]).To(BeNumerically(">=", 15))
})
})
})
Expand Down
41 changes: 41 additions & 0 deletions vendor/github.com/google/uuid/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/google/uuid/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/google/uuid/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions vendor/github.com/google/uuid/dce.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/google/uuid/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions vendor/github.com/google/uuid/hash.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2474f7a

Please sign in to comment.