Skip to content

Commit

Permalink
increase mx lock cycles in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade authored and kobergj committed Nov 7, 2022
1 parent eecc16c commit 929383d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/filelocks/filelocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func acquireLock(file string, write bool) (*flock.Flock, error) {
}

var flock *flock.Flock
for i := 1; i <= 10; i++ {
for i := 1; i <= _lockCyclesValue; i++ {
if flock = getMutexedFlock(n); flock != nil {
break
}
Expand Down
29 changes: 20 additions & 9 deletions pkg/storage/utils/filelocks/filelocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ func TestAcquireWriteLock(t *testing.T) {
file, fin, _ := filelocks.FileFactory()
defer fin()

filelocks.SetMaxLockCycles(90)

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()

l, err := filelocks.AcquireWriteLock(file)
assert.Nil(t, err)
require.NotNil(t, l)
assert.Equal(t, true, l.Locked())
assert.Equal(t, false, l.RLocked())

err = filelocks.ReleaseLock(l)
assert.Nil(t, err)
defer func() {
err = filelocks.ReleaseLock(l)
assert.Nil(t, err)
}()

wg.Done()
assert.Equal(t, true, l.Locked())
assert.Equal(t, false, l.RLocked())
}()
}

Expand All @@ -55,20 +60,26 @@ func TestAcquireReadLock(t *testing.T) {
file, fin, _ := filelocks.FileFactory()
defer fin()

filelocks.SetMaxLockCycles(90)

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()

l, err := filelocks.AcquireReadLock(file)
assert.Nil(t, err)
require.NotNil(t, l)

defer func() {
err = filelocks.ReleaseLock(l)
assert.Nil(t, err)
}()

assert.Equal(t, false, l.Locked())
assert.Equal(t, true, l.RLocked())

err = filelocks.ReleaseLock(l)
assert.Nil(t, err)

wg.Done()
}()
}

Expand Down

0 comments on commit 929383d

Please sign in to comment.