55 "path/filepath"
66 "regexp"
77 "slices"
8+ "sync"
89 "time"
910
1011 "github.com/cloudfoundry/cf-test-helpers/v2/cf"
@@ -71,9 +72,11 @@ var _ = RoutingDescribe("Per-Route Options", func() {
7172 Context ("when it's set to round-robin" , func () {
7273 It ("distributes requests evenly" , func () {
7374 doraUrl := fmt .Sprintf ("%s%s.%s" , Config .Protocol (), roundRobinHost , Config .GetAppsDomain ())
74-
75+ var wg sync. WaitGroup
7576 for i := 0 ; i < 10 ; i ++ {
77+ wg .Add (1 )
7678 go func () {
79+ defer wg .Done ()
7780 defer GinkgoRecover ()
7881 Expect (helpers .Curl (Config , fmt .Sprintf ("%s/delay/20" , doraUrl ), "-H" , fmt .Sprintf ("X-Cf-App-Instance: %s:0" , appId ))).To (Exit (0 ))
7982 }()
@@ -86,7 +89,7 @@ var _ = RoutingDescribe("Per-Route Options", func() {
8689 reqCount [slices .Index (instanceIds [:], string (id ))] += 1
8790 time .Sleep (10 * time .Millisecond )
8891 }
89-
92+ wg . Wait ()
9093 // allow for some wiggle-room
9194 Expect (reqCount [0 ]).To (BeNumerically (">=" , 8 ))
9295 Expect (reqCount [1 ]).To (BeNumerically (">=" , 8 ))
@@ -96,9 +99,11 @@ var _ = RoutingDescribe("Per-Route Options", func() {
9699 Context ("when it's set to least-connection" , func () {
97100 It ("always sends the request to the instance with less active connections" , func () {
98101 doraUrl := fmt .Sprintf ("%s%s.%s" , Config .Protocol (), leastConnHost , Config .GetAppsDomain ())
99-
102+ var wg sync. WaitGroup
100103 for i := 0 ; i < 10 ; i ++ {
104+ wg .Add (1 )
101105 go func () {
106+ defer wg .Done ()
102107 defer GinkgoRecover ()
103108 Expect (helpers .Curl (Config , fmt .Sprintf ("%s/delay/20" , doraUrl ), "-H" , fmt .Sprintf ("X-Cf-App-Instance: %s:0" , appId ))).To (Exit (0 ))
104109 }()
@@ -111,10 +116,10 @@ var _ = RoutingDescribe("Per-Route Options", func() {
111116 reqCount [slices .Index (instanceIds [:], string (id ))] += 1
112117 time .Sleep (10 * time .Millisecond )
113118 }
114-
119+ wg . Wait ()
115120 // allow for some wiggle-room
116- Expect (reqCount [0 ]).To (BeNumerically ("<=" , 5 ))
117- Expect (reqCount [1 ]).To (BeNumerically (">=" , 15 ))
121+ Expect (reqCount [0 ]).To (BeNumerically ("<=" , 8 ))
122+ Expect (reqCount [1 ]).To (BeNumerically (">=" , 12 ))
118123 })
119124 })
120125 })
0 commit comments