Add first unit test for authApplierV3

This contains a slight refactoring to expose enough information
to write meaningful tests for auth applier v3.

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
This commit is contained in:
Thomas Jungblut
2023-06-16 09:42:09 +02:00
parent b2fb75d147
commit 423f951409
3 changed files with 142 additions and 9 deletions

View File

@@ -281,12 +281,7 @@ func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {
// 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{}),
revokec: make(chan struct{}),
}
l := NewLease(id, ttl)
le.mu.Lock()
defer le.mu.Unlock()
@@ -838,6 +833,15 @@ type Lease struct {
revokec chan struct{}
}
func NewLease(id LeaseID, ttl int64) *Lease {
return &Lease{
ID: id,
ttl: ttl,
itemSet: make(map[LeaseItem]struct{}),
revokec: make(chan struct{}),
}
}
func (l *Lease) expired() bool {
return l.Remaining() <= 0
}
@@ -861,6 +865,13 @@ func (l *Lease) TTL() int64 {
return l.ttl
}
// SetLeaseItem sets the given lease item, this func is thread-safe
func (l *Lease) SetLeaseItem(item LeaseItem) {
l.mu.Lock()
defer l.mu.Unlock()
l.itemSet[item] = struct{}{}
}
// RemainingTTL returns the last checkpointed remaining TTL of the lease.
// TODO(jpbetz): do not expose this utility method
func (l *Lease) RemainingTTL() int64 {