refactor clean up
parent
797d996535
commit
49c55477e5
|
@ -3,7 +3,6 @@ package store
|
|||
import (
|
||||
"path"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
|
@ -36,10 +35,6 @@ type Node struct {
|
|||
|
||||
// A reference to the store this node is attached to.
|
||||
store *store
|
||||
|
||||
// ensure we only delete the node once
|
||||
// expire and remove may try to delete a node twice
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
// newKV creates a Key-Value pair
|
||||
|
|
|
@ -2,7 +2,7 @@ package store
|
|||
|
||||
import (
|
||||
"testing"
|
||||
//"time"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -84,11 +84,12 @@ func TestStoreStatsDeleteFail(t *testing.T) {
|
|||
assert.Equal(t, uint64(1), s.Stats.DeleteFail, "")
|
||||
}
|
||||
|
||||
// Ensure that the number of expirations is recorded in the stats.
|
||||
// func TestStoreStatsExpireCount(t *testing.T) {
|
||||
// s := newStore()
|
||||
// s.Create("/foo", "bar", false, time.Now().Add(5 * time.Millisecond), 3, 1)
|
||||
// assert.Equal(t, uint64(0), s.Stats.ExpireCount, "")
|
||||
// time.Sleep(10 * time.Millisecond)
|
||||
// assert.Equal(t, uint64(1), s.Stats.ExpireCount, "")
|
||||
// }
|
||||
//Ensure that the number of expirations is recorded in the stats.
|
||||
func TestStoreStatsExpireCount(t *testing.T) {
|
||||
s := newStore()
|
||||
go mockSyncService(s.deleteExpiredKeys)
|
||||
s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond), 3, 1)
|
||||
assert.Equal(t, uint64(0), s.Stats.ExpireCount, "")
|
||||
time.Sleep(600 * time.Millisecond)
|
||||
assert.Equal(t, uint64(1), s.Stats.ExpireCount, "")
|
||||
}
|
||||
|
|
|
@ -448,6 +448,7 @@ func (s *store) deleteExpiredKeys(cutoff time.Time) {
|
|||
s.ttlKeyHeap.pop()
|
||||
node.Remove(true, nil)
|
||||
|
||||
s.Stats.Inc(ExpireCount)
|
||||
s.WatcherHub.notify(newEvent(Expire, node.Path, s.Index, s.Term))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue