Browse Source

refactor clean up

Xiang Li 12 years ago
parent
commit
49c55477e5
3 changed files with 11 additions and 14 deletions
  1. 0 5
      store/node.go
  2. 10 9
      store/stats_test.go
  3. 1 0
      store/store.go

+ 0 - 5
store/node.go

@@ -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

+ 10 - 9
store/stats_test.go

@@ -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, "")
+}

+ 1 - 0
store/store.go

@@ -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))
 	}
 }