Adding Concurrency in Pool Manager (#1698)

Concurrency in the pool manager allows specializing pods concurrently based on a specified limit. 

Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
Rahul Bhati
2020-09-16 18:48:08 +05:30
committed by GitHub
co-authored by Vishal
parent c1ac7fcd38
commit f3fe3123b3
25 changed files with 659 additions and 402 deletions
+54
View File
@@ -0,0 +1,54 @@
package poolcache
import (
"log"
"testing"
"time"
)
func checkErr(err error) {
if err != nil {
log.Panicf("err: %v", err)
}
}
func TestPoolCache(t *testing.T) {
c := NewPoolCache()
c.SetValue("func", "ip", "value")
c.SetValue("func2", "ip2", "value2")
c.SetValue("func2", "ip22", "value22")
cc := c.ListValue()
if len(cc) != 3 {
log.Panicf("expected 2 items")
}
active := c.GetTotalAvailable("func2")
if active != 2 {
log.Panicf("expected 2 items")
}
c.DeleteValue("func2", "ip2")
c.MarkAvailable("func", "ip")
_, err := c.GetValue("func")
checkErr(err)
c.DeleteValue("func", "ip")
_, err = c.GetValue("func")
if err == nil {
log.Panicf("found deleted element")
}
c.SetValue("expires", "42", "all answers")
time.Sleep(150 * time.Millisecond)
_, err = c.GetValue("expires")
if err == nil {
log.Panicf("found expired element")
}
}