1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add pool reuse test to unit tests

Add a test to confirm that the pool allocator will iterate through all
the pools even if some earlier ones were freed before coming back to
previously allocated pools.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
This commit is contained in:
Chris Telfer 2018-06-01 14:03:20 -04:00
parent cc8b2cac28
commit e31e906e4e

View file

@ -590,6 +590,45 @@ func TestGetSameAddress(t *testing.T) {
}
}
func TestPoolAllocationReuse(t *testing.T) {
for _, store := range []bool{false, true} {
a, err := getAllocator(store)
assert.NoError(t, err)
// First get all pools until they are exhausted to
pList := []string{}
pool, _, _, err := a.RequestPool(localAddressSpace, "", "", nil, false)
for err == nil {
pList = append(pList, pool)
pool, _, _, err = a.RequestPool(localAddressSpace, "", "", nil, false)
}
nPools := len(pList)
for _, pool := range pList {
if err := a.ReleasePool(pool); err != nil {
t.Fatal(err)
}
}
// Now try to allocate then free nPool pools sequentially.
// Verify that we don't see any repeat networks even though
// we have freed them.
seen := map[string]bool{}
for i := 0; i < nPools; i++ {
pool, nw, _, err := a.RequestPool(localAddressSpace, "", "", nil, false)
if err != nil {
t.Fatal(err)
}
if _, ok := seen[nw.String()]; ok {
t.Fatalf("Network %s was reused before exhausing the pool list", nw.String())
}
seen[nw.String()] = true
if err := a.ReleasePool(pool); err != nil {
t.Fatal(err)
}
}
}
}
func TestGetAddressSubPoolEqualPool(t *testing.T) {
for _, store := range []bool{false, true} {
a, err := getAllocator(store)