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:
parent
cc8b2cac28
commit
e31e906e4e
1 changed files with 39 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue