mirror of https://github.com/status-im/consul.git
consul: Adding PendingExpiration
This commit is contained in:
parent
10604a6fa8
commit
3bcf957d95
|
@ -102,6 +102,13 @@ func (t *TombstoneGC) Hint(index uint64) {
|
|||
}
|
||||
}
|
||||
|
||||
// PendingExpiration is used to check if any expirations are pending
|
||||
func (t *TombstoneGC) PendingExpiration() bool {
|
||||
t.expiresLock.Lock()
|
||||
defer t.expiresLock.Unlock()
|
||||
return len(t.expires) > 0
|
||||
}
|
||||
|
||||
// nextExpires is used to calculate the next experation time
|
||||
func (t *TombstoneGC) nextExpires() time.Time {
|
||||
expires := time.Now().Add(t.ttl)
|
||||
|
|
|
@ -30,6 +30,10 @@ func TestTombstoneGC(t *testing.T) {
|
|||
t.Fatalf("should fail")
|
||||
}
|
||||
|
||||
if gc.PendingExpiration() {
|
||||
t.Fatalf("should not be pending")
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
gc.Hint(100)
|
||||
|
||||
|
@ -38,6 +42,10 @@ func TestTombstoneGC(t *testing.T) {
|
|||
gc.Hint(120)
|
||||
gc.Hint(125)
|
||||
|
||||
if !gc.PendingExpiration() {
|
||||
t.Fatalf("should be pending")
|
||||
}
|
||||
|
||||
select {
|
||||
case index := <-gc.ExpireCh():
|
||||
end := time.Now()
|
||||
|
@ -75,9 +83,17 @@ func TestTombstoneGC_Expire(t *testing.T) {
|
|||
t.Fatalf("should fail")
|
||||
}
|
||||
|
||||
if gc.PendingExpiration() {
|
||||
t.Fatalf("should not be pending")
|
||||
}
|
||||
|
||||
gc.Hint(100)
|
||||
gc.Reset()
|
||||
|
||||
if gc.PendingExpiration() {
|
||||
t.Fatalf("should not be pending")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-gc.ExpireCh():
|
||||
t.Fatalf("shoudl be reset")
|
||||
|
|
Loading…
Reference in New Issue