@@ -41,20 +41,6 @@ var _ = RoutingDescribe("Per-Route Options", func() {
4141 return fmt .Sprintf ("%s%s.%s" , Config .Protocol (), host , Config .GetAppsDomain ())
4242 }
4343
44- // Helper function to create busy background requests on a specific CF instance
45- createBusyInstance := func (url , instanceIndex string , count int ) * sync.WaitGroup {
46- var wg sync.WaitGroup
47- for i := 0 ; i < count ; i ++ {
48- wg .Add (1 )
49- go func () {
50- defer wg .Done ()
51- defer GinkgoRecover ()
52- helpers .Curl (Config , fmt .Sprintf ("%s/delay/10" , url ), "-H" , fmt .Sprintf ("X-Cf-App-Instance: %s:%s" , appId , instanceIndex ))
53- }()
54- }
55- return & wg
56- }
57-
5844 Context ("when an app sets the loadbalancing algorithm" , func () {
5945 BeforeEach (func () {
6046 workflowhelpers .AsUser (TestSetup .AdminUserContext (), TestSetup .ShortTimeout (), func () {
@@ -156,10 +142,6 @@ var _ = RoutingDescribe("Per-Route Options", func() {
156142 It ("routes requests to the same instance" , func () {
157143 doraUrl := buildUrl (hashBasedRoutingHost )
158144 hashHeader := "X-Hash-Header: 1"
159- cfInstanceIndex := helpers .Curl (Config , fmt .Sprintf ("%s/env/INSTANCE_INDEX" , doraUrl ), "-H" , hashHeader ).Wait ().Out .Contents ()
160-
161- // Create background load on the target instance
162- wg := createBusyInstance (doraUrl , string (cfInstanceIndex ), 10 )
163145
164146 reqCount := [2 ]int {0 , 0 }
165147 for i := 0 ; i < 20 ; i ++ {
@@ -169,32 +151,28 @@ var _ = RoutingDescribe("Per-Route Options", func() {
169151
170152 // All requests with the same hash should go to the same instance
171153 Expect (reqCount [0 ] == 20 || reqCount [1 ] == 20 ).To (BeTrue (), "All 20 requests should be routed to the same instance" )
172- wg .Wait ()
173154 })
174155 })
175156 Context ("when the requests contain the different hash headers" , func () {
176157 It ("distributes requests evenly" , func () {
177158 doraUrl := buildUrl (hashBasedRoutingHost )
178- // Create background load on the instance with index 0
179- wg := createBusyInstance (doraUrl , "0" , 10 )
180159
181160 reqCount := [2 ]int {0 , 0 }
182- requestsToSent := 100
183- for i := 0 ; i < requestsToSent ; i ++ {
161+ requestsToSend := 100
162+ for i := 0 ; i < requestsToSend ; i ++ {
184163 // Generate random hash header
185164 uuid := make ([]byte , 16 )
186165 rand .Read (uuid )
187- uuidStr := fmt .Sprintf ("%x" , uuid )
166+ randomHashValue := fmt .Sprintf ("%x" , uuid )
188167
189- id := helpers .Curl (Config , fmt .Sprintf ("%s/id" , doraUrl ), "-H" , fmt .Sprintf ("X-Hash-Header: %s" , uuidStr )).Wait ().Out .Contents ()
168+ id := helpers .Curl (Config , fmt .Sprintf ("%s/id" , doraUrl ), "-H" , fmt .Sprintf ("X-Hash-Header: %s" , randomHashValue )).Wait ().Out .Contents ()
190169 reqCount [slices .Index (instanceIds [:], string (id ))] += 1
191170 }
192171
193172 // allow for some wiggle-room
194- expectedWithTolerance := (requestsToSent / 2 ) - (requestsToSent * 10 / 100 )
195- Expect (reqCount [0 ]).To (BeNumerically (">=" , expectedWithTolerance ))
196- Expect (reqCount [1 ]).To (BeNumerically (">=" , expectedWithTolerance ))
197- wg .Wait ()
173+ tolerance := 10
174+ Expect (reqCount [0 ]).To (BeNumerically (">=" , (requestsToSend / 2 )- tolerance ), "Approximately half of requests should be routed to the first instance" )
175+ Expect (reqCount [1 ]).To (BeNumerically (">=" , (requestsToSend / 2 )- tolerance ), "Approximately half of requests should be routed to the second instance" )
198176 })
199177 })
200178 })
0 commit comments