diff --git a/assets/dora/man_route_opt_lb.yml b/assets/dora/man_route_opt_lb.yml index 1ab096143..fc095191d 100644 --- a/assets/dora/man_route_opt_lb.yml +++ b/assets/dora/man_route_opt_lb.yml @@ -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: diff --git a/routing/per_route_options.go b/routing/per_route_options.go index 64dd1ec23..a0e4e9cb8 100644 --- a/routing/per_route_options.go +++ b/routing/per_route_options.go @@ -16,19 +16,24 @@ 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(), @@ -36,12 +41,22 @@ var _ = RoutingDescribe("Per-Route Options", func() { "-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() { @@ -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() { @@ -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() { @@ -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)) }) }) })