Use concurrency in poolmanager as per old behaviour (#2876)

* Use concurrency in poolmanager as per old behaviour
* Update code comments

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2023-11-21 13:34:17 +05:30
committed by GitHub
parent d23ed572f9
commit b85ba9e419
2 changed files with 33 additions and 15 deletions
+17 -10
View File
@@ -224,6 +224,7 @@ func TestPoolCacheRequests(t *testing.T) {
simultaneous = 1
}
for i := 1; i <= tt.requests; i++ {
reqno := i
wg.Add(1)
go func(reqno int) {
defer wg.Done()
@@ -231,10 +232,11 @@ func TestPoolCacheRequests(t *testing.T) {
if err != nil {
code, _ := ferror.GetHTTPError(err)
if code == http.StatusNotFound {
p.SetSvcValue(context.Background(), key, fmt.Sprintf("svc-%d", svcCounter), &FuncSvc{
Name: "value",
}, resource.MustParse("45m"), tt.rpp, tt.retainPods)
atomic.AddUint64(&svcCounter, 1)
address := fmt.Sprintf("svc-%d", atomic.LoadUint64(&svcCounter))
p.SetSvcValue(context.Background(), key, address, &FuncSvc{
Name: address,
}, resource.MustParse("45m"), tt.rpp, tt.retainPods)
} else {
t.Log(reqno, "=>", err)
atomic.AddUint64(&failedRequests, 1)
@@ -244,9 +246,12 @@ func TestPoolCacheRequests(t *testing.T) {
t.Log(reqno, "=>", "svc is nil")
atomic.AddUint64(&failedRequests, 1)
}
// } else {
// t.Log(reqno, "=>", svc.Name)
// }
}
}(i)
if i%simultaneous == 0 {
}(reqno)
if reqno%simultaneous == 0 {
wg.Wait()
}
}
@@ -258,10 +263,11 @@ func TestPoolCacheRequests(t *testing.T) {
for i := 0; i < tt.concurrency; i++ {
for j := 0; j < tt.rpp; j++ {
wg.Add(1)
go func(i int) {
svcno := i
go func(svcno int) {
defer wg.Done()
p.MarkAvailable(key, fmt.Sprintf("svc-%d", i))
}(i)
p.MarkAvailable(key, fmt.Sprintf("svc-%d", svcno+1))
}(svcno)
}
}
wg.Wait()
@@ -270,8 +276,9 @@ func TestPoolCacheRequests(t *testing.T) {
UID: "func",
Generation: 2,
}
p.SetSvcValue(context.Background(), newKey, fmt.Sprintf("svc-%d", svcCounter), &FuncSvc{
Name: "value",
address := fmt.Sprintf("svc-%d", svcCounter)
p.SetSvcValue(context.Background(), newKey, address, &FuncSvc{
Name: address,
}, resource.MustParse("45m"), tt.rpp, tt.retainPods)
funcSvc := p.ListAvailableValue()
require.Equal(t, tt.concurrency, len(funcSvc))