lessor: fix go vet, goword warnings, and unreliable test

This commit is contained in:
Anthony Romano 2016-06-17 12:13:01 -07:00
parent 016be1ef31
commit ea21b8ee1f
2 changed files with 7 additions and 5 deletions

View File

@ -54,7 +54,7 @@ type RangeDeleter interface {
DeleteRange(key, end []byte) (int64, int64)
}
// A Lessor is the owner of leases. It can grant, revoke, renew and modify leases for lessee.
// Lessor owns leases. It can grant, revoke, renew and modify leases for lessee.
type Lessor interface {
// SetRangeDeleter sets the RangeDeleter to the Lessor.
// Lessor deletes the items in the revoked or expired lease from the
@ -172,13 +172,13 @@ func (le *lessor) SetRangeDeleter(rd RangeDeleter) {
le.rd = rd
}
// TODO: when lessor is under high load, it should give out lease
// with longer TTL to reduce renew load.
func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {
if id == NoLease {
return nil, ErrLeaseNotFound
}
// TODO: when lessor is under high load, it should give out lease
// with longer TTL to reduce renew load.
l := &Lease{ID: id, TTL: ttl, itemSet: make(map[LeaseItem]struct{})}
le.mu.Lock()

View File

@ -19,6 +19,7 @@ import (
"os"
"path"
"reflect"
"sort"
"testing"
"time"
@ -96,7 +97,7 @@ func TestLessorRevoke(t *testing.T) {
{"bar"},
}
if err := le.Attach(l.ID, items); err != nil {
if err = le.Attach(l.ID, items); err != nil {
t.Fatalf("failed to attach items to the lease: %v", err)
}
@ -108,7 +109,8 @@ func TestLessorRevoke(t *testing.T) {
t.Errorf("got revoked lease %x", l.ID)
}
wdeleted := []string{"foo_", "bar_"}
wdeleted := []string{"bar_", "foo_"}
sort.Sort(sort.StringSlice(fd.deleted))
if !reflect.DeepEqual(fd.deleted, wdeleted) {
t.Errorf("deleted= %v, want %v", fd.deleted, wdeleted)
}