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 9e76848
Show file tree
Hide file tree
Showing 2 changed files with 26 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
33 changes: 24 additions & 9 deletions routing/per_route_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,47 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/satori/go.uuid"
)

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.NewV4().String()
roundRobinHost = "dora-rr-" + uuid.NewV4().String()
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.FromString(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

0 comments on commit 9e76848

Please sign in to comment.