Skip to content
Snippets Groups Projects
Commit efe8c6c8 authored by liqiankun.1111's avatar liqiankun.1111
Browse files

fix: fix return lock infer

parent 4d8b467c
No related branches found
No related tags found
No related merge requests found
...@@ -88,7 +88,7 @@ func (r *DBLock) lock(ctx context.Context, key string) (keyLock interface{}, err ...@@ -88,7 +88,7 @@ func (r *DBLock) lock(ctx context.Context, key string) (keyLock interface{}, err
// resource updated by others // resource updated by others
return nil, ErrConflict return nil, ErrConflict
} }
return lock, nil return &lock, nil
} }
func (r *DBLock) UnLock(ctx context.Context, keyLock interface{}) error { func (r *DBLock) UnLock(ctx context.Context, keyLock interface{}) error {
......
...@@ -35,8 +35,11 @@ func TestLock(t *testing.T) { ...@@ -35,8 +35,11 @@ func TestLock(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
r := l.(*ResourceLock) r := l.(*ResourceLock)
assert.True(t, len(r.LockerID) > 0) assert.True(t, len(r.LockerID) > 0)
// 重试5次,至少耗时500ms // 测试lock 过期场景
_, err = lock.Lock(context.Background(), "abc") time.Sleep(1 * time.Second)
l, err = lock.Lock(context.Background(), "abc")
assert.NoError(t, err)
err = lock.UnLock(context.Background(), l)
assert.NoError(t, err) assert.NoError(t, err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment