Skip to content

Commit

Permalink
kvstore/allocator: test for stale locks before acquiring lock
Browse files Browse the repository at this point in the history
[ upstream commit 9ba79ef ]

Checking for stale locks after acquiring the 1st lock might lead into
test flakes so we should test for them before acquiring the 1st lock.

Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm authored and gandro committed Feb 3, 2020
1 parent 979b227 commit 3288d17
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/kvstore/allocator/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func (s *AllocatorSuite) TestRunLocksGC(c *C) {
allocator, err := NewAllocator(allocatorName, TestType(""), WithMax(maxID), WithSuffix("a"), WithoutGC())
c.Assert(err, IsNil)
shortKey := TestType("1;")

staleLocks := map[string]kvstore.Value{}
staleLocks, err = allocator.RunLocksGC(staleLocks)
c.Assert(err, IsNil)
c.Assert(len(staleLocks), Equals, 0)

var (
lock1, lock2 kvstore.KVLocker
gotLock1 = make(chan struct{})
Expand Down Expand Up @@ -188,10 +194,6 @@ func (s *AllocatorSuite) TestRunLocksGC(c *C) {
c.Assert(err, IsNil)
close(gotLock2)
}()
staleLocks := map[string]kvstore.Value{}
staleLocks, err = allocator.RunLocksGC(staleLocks)
c.Assert(err, IsNil)
c.Assert(len(staleLocks), Equals, 0)

// Wait until lock1 is gotten.
c.Assert(testutils.WaitUntil(func() bool {
Expand Down

0 comments on commit 3288d17

Please sign in to comment.