Merge pull request #41 from damz/pr/rados-lock

Fix bogus duration handling in IOContext.Lock*

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2017-07-28 07:40:07 -07:00 committed by GitHub
commit 81e4191e13
2 changed files with 24 additions and 2 deletions

View File

@ -649,7 +649,7 @@ func (ioctx *IOContext) LockExclusive(oid, name, cookie, desc string, duration t
var c_duration C.struct_timeval var c_duration C.struct_timeval
if duration != 0 { if duration != 0 {
tv := syscall.NsecToTimeval(time.Now().Add(duration).UnixNano()) tv := syscall.NsecToTimeval(duration.Nanoseconds())
c_duration = C.struct_timeval{tv_sec: C.__time_t(tv.Sec), tv_usec: C.__suseconds_t(tv.Usec)} c_duration = C.struct_timeval{tv_sec: C.__time_t(tv.Sec), tv_usec: C.__suseconds_t(tv.Usec)}
} }
@ -698,7 +698,7 @@ func (ioctx *IOContext) LockShared(oid, name, cookie, tag, desc string, duration
var c_duration C.struct_timeval var c_duration C.struct_timeval
if duration != 0 { if duration != 0 {
tv := syscall.NsecToTimeval(time.Now().Add(duration).UnixNano()) tv := syscall.NsecToTimeval(duration.Nanoseconds())
c_duration = C.struct_timeval{tv_sec: C.__time_t(tv.Sec), tv_usec: C.__suseconds_t(tv.Usec)} c_duration = C.struct_timeval{tv_sec: C.__time_t(tv.Sec), tv_usec: C.__suseconds_t(tv.Usec)}
} }

View File

@ -976,6 +976,28 @@ func TestLocking(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 0, len(info.Clients)) assert.Equal(t, 0, len(info.Clients))
// lock sh with duration
res, err = pool.LockShared("obj", "myLock", "myCookie", "", "a description", time.Millisecond, nil)
assert.NoError(t, err)
assert.Equal(t, 0, res)
// verify lock sh expired
time.Sleep(time.Second)
info, err = pool.ListLockers("obj", "myLock")
assert.NoError(t, err)
assert.Equal(t, 0, len(info.Clients))
// lock sh with duration
res, err = pool.LockExclusive("obj", "myLock", "myCookie", "a description", time.Millisecond, nil)
assert.NoError(t, err)
assert.Equal(t, 0, res)
// verify lock sh expired
time.Sleep(time.Second)
info, err = pool.ListLockers("obj", "myLock")
assert.NoError(t, err)
assert.Equal(t, 0, len(info.Clients))
pool.Destroy() pool.Destroy()
conn.Shutdown() conn.Shutdown()
} }