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

ipam/allocator_test: Test pool double-release behavior

Releasing a pool which has already been released should fail; this
change increases coverage by a fraction by exercising this path.

Signed-off-by: Euan Harris <euan.harris@docker.com>
This commit is contained in:
Euan Harris 2018-05-18 17:02:03 +01:00
parent 2f2811dd14
commit 35a81f8173

View file

@ -288,6 +288,42 @@ func TestAddSubnets(t *testing.T) {
}
}
// TestDoublePoolRelease tests that releasing a pool which has already
// been released raises an error.
func TestDoublePoolRelease(t *testing.T) {
for _, store := range []bool{false, true} {
for _, repeats := range []int{0, 1, 10} {
a, err := getAllocator(store)
assert.NoError(t, err)
// Request initial pool allocation
pid0, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
assert.NoError(t, err)
// Re-request the same pool
for i := 0; i < repeats; i++ {
pidN, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
assert.NoError(t, err)
assert.Equal(t, pid0, pidN)
}
// Release the repeats
for i := 0; i < repeats; i++ {
err = a.ReleasePool(pid0)
assert.NoError(t, err)
}
// Release the initial request
err = a.ReleasePool(pid0)
assert.NoError(t, err)
// Releasing again fails
err = a.ReleasePool(pid0)
assert.Error(t, err)
}
}
}
func TestAddReleasePoolID(t *testing.T) {
for _, store := range []bool{false, true} {
a, err := getAllocator(store)