Browse Source

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

Anthony Romano 9 years ago
parent
commit
ea21b8ee1f
2 changed files with 7 additions and 5 deletions
  1. 3 3
      lease/lessor.go
  2. 4 2
      lease/lessor_test.go

+ 3 - 3
lease/lessor.go

@@ -54,7 +54,7 @@ type RangeDeleter interface {
 	DeleteRange(key, end []byte) (int64, int64)
 	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 {
 type Lessor interface {
 	// SetRangeDeleter sets the RangeDeleter to the Lessor.
 	// SetRangeDeleter sets the RangeDeleter to the Lessor.
 	// Lessor deletes the items in the revoked or expired lease from the
 	// 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
 	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) {
 func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {
 	if id == NoLease {
 	if id == NoLease {
 		return nil, ErrLeaseNotFound
 		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{})}
 	l := &Lease{ID: id, TTL: ttl, itemSet: make(map[LeaseItem]struct{})}
 
 
 	le.mu.Lock()
 	le.mu.Lock()

+ 4 - 2
lease/lessor_test.go

@@ -19,6 +19,7 @@ import (
 	"os"
 	"os"
 	"path"
 	"path"
 	"reflect"
 	"reflect"
+	"sort"
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
@@ -96,7 +97,7 @@ func TestLessorRevoke(t *testing.T) {
 		{"bar"},
 		{"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)
 		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)
 		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) {
 	if !reflect.DeepEqual(fd.deleted, wdeleted) {
 		t.Errorf("deleted= %v, want %v", fd.deleted, wdeleted)
 		t.Errorf("deleted= %v, want %v", fd.deleted, wdeleted)
 	}
 	}