Browse Source

Merge pull request #1153 from jonboulle/1153_etcd_index

X-Etcd-Index off by one
Jonathan Boulle 11 years ago
parent
commit
56c64ab2e8
2 changed files with 92 additions and 5 deletions
  1. 2 2
      store/store.go
  2. 90 3
      store/store_test.go

+ 2 - 2
store/store.go

@@ -275,7 +275,7 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
 
 	nextIndex := s.CurrentIndex + 1
 	e := newEvent(Delete, nodePath, nextIndex, n.CreatedIndex)
-	e.EtcdIndex = s.CurrentIndex
+	e.EtcdIndex = nextIndex
 	e.PrevNode = n.Repr(false, false)
 	eNode := e.Node
 
@@ -414,7 +414,7 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (
 	}
 
 	e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex)
-	e.EtcdIndex = s.CurrentIndex
+	e.EtcdIndex = nextIndex
 	e.PrevNode = n.Repr(false, false)
 	eNode := e.Node
 

+ 90 - 3
store/store_test.go

@@ -28,8 +28,10 @@ import (
 func TestStoreGetValue(t *testing.T) {
 	s := newStore()
 	s.Create("/foo", false, "bar", false, Permanent)
+	var eidx uint64 = 1
 	e, err := s.Get("/foo", false, false)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "get", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
@@ -46,8 +48,10 @@ func TestStoreGetDirectory(t *testing.T) {
 	s.Create("/foo/baz/bat", false, "Y", false, Permanent)
 	s.Create("/foo/baz/_hidden", false, "*", false, Permanent)
 	s.Create("/foo/baz/ttl", false, "Y", false, time.Now().Add(time.Second*3))
+	var eidx uint64 = 7
 	e, err := s.Get("/foo", true, false)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "get", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, len(e.Node.Nodes), 2, "")
@@ -89,8 +93,10 @@ func TestStoreGetSorted(t *testing.T) {
 	s.Create("/foo/y", true, "", false, Permanent)
 	s.Create("/foo/y/a", false, "0", false, Permanent)
 	s.Create("/foo/y/b", false, "0", false, Permanent)
+	var eidx uint64 = 6
 	e, err := s.Get("/foo", true, true)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	var yNodes NodeExterns
 	for _, node := range e.Node.Nodes {
 		switch node.Key {
@@ -116,8 +122,10 @@ func TestSet(t *testing.T) {
 	s := newStore()
 
 	// Set /foo=""
+	var eidx uint64 = 1
 	e, err := s.Set("/foo", false, "", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -128,8 +136,10 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(1), "")
 
 	// Set /foo="bar"
+	eidx = 2
 	e, err = s.Set("/foo", false, "bar", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -144,8 +154,10 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, *e.PrevNode.Value, "", "")
 	assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
 	// Set /foo="baz" (for testing prevNode)
+	eidx = 3
 	e, err = s.Set("/foo", false, "baz", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -161,8 +173,10 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(2), "")
 
 	// Set /dir as a directory
+	eidx = 4
 	e, err = s.Set("/dir", true, "", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/dir", "")
 	assert.True(t, e.Node.Dir, "")
@@ -177,8 +191,10 @@ func TestSet(t *testing.T) {
 func TestStoreCreateValue(t *testing.T) {
 	s := newStore()
 	// Create /foo=bar
+	var eidx uint64 = 1
 	e, err := s.Create("/foo", false, "bar", false, Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -189,8 +205,10 @@ func TestStoreCreateValue(t *testing.T) {
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(1), "")
 
 	// Create /empty=""
+	eidx = 2
 	e, err = s.Create("/empty", false, "", false, Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/empty", "")
 	assert.False(t, e.Node.Dir, "")
@@ -205,8 +223,10 @@ func TestStoreCreateValue(t *testing.T) {
 // Ensure that the store can create a new directory if it doesn't already exist.
 func TestStoreCreateDirectory(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	e, err := s.Create("/foo", true, "", false, Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.True(t, e.Node.Dir, "")
@@ -234,8 +254,10 @@ func TestStoreUpdateValue(t *testing.T) {
 	// create /foo=bar
 	s.Create("/foo", false, "bar", false, Permanent)
 	// update /foo="bzr"
+	var eidx uint64 = 2
 	e, err := s.Update("/foo", "baz", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -250,10 +272,13 @@ func TestStoreUpdateValue(t *testing.T) {
 
 	e, _ = s.Get("/foo", false, false)
 	assert.Equal(t, *e.Node.Value, "baz", "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 
 	// update /foo=""
+	eidx = 3
 	e, err = s.Update("/foo", "", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
@@ -267,6 +292,7 @@ func TestStoreUpdateValue(t *testing.T) {
 	assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(2), "")
 
 	e, _ = s.Get("/foo", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, *e.Node.Value, "", "")
 }
 
@@ -292,10 +318,12 @@ func TestStoreUpdateValueTTL(t *testing.T) {
 	}()
 	go mockSyncService(s.DeleteExpiredKeys, c)
 
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	_, err := s.Update("/foo", "baz", time.Now().Add(500*time.Millisecond))
 	e, _ := s.Get("/foo", false, false)
 	assert.Equal(t, *e.Node.Value, "baz", "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 
 	time.Sleep(600 * time.Millisecond)
 	e, err = s.Get("/foo", false, false)
@@ -313,12 +341,15 @@ func TestStoreUpdateDirTTL(t *testing.T) {
 	}()
 	go mockSyncService(s.DeleteExpiredKeys, c)
 
+	var eidx uint64 = 3
 	s.Create("/foo", true, "", false, Permanent)
 	s.Create("/foo/bar", false, "baz", false, Permanent)
 	e, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond))
 	assert.Equal(t, e.Node.Dir, true, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	e, _ = s.Get("/foo/bar", false, false)
 	assert.Equal(t, *e.Node.Value, "baz", "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 
 	time.Sleep(600 * time.Millisecond)
 	e, err = s.Get("/foo/bar", false, false)
@@ -329,11 +360,13 @@ func TestStoreUpdateDirTTL(t *testing.T) {
 // Ensure that the store can delete a value.
 func TestStoreDeleteValue(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, err := s.Delete("/foo", false, false)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "delete", "")
-	// check pervNode
+	// check prevNode
 	assert.NotNil(t, e.PrevNode, "")
 	assert.Equal(t, e.PrevNode.Key, "/foo", "")
 	assert.Equal(t, *e.PrevNode.Value, "bar", "")
@@ -343,13 +376,15 @@ func TestStoreDeleteValue(t *testing.T) {
 func TestStoreDeleteDiretory(t *testing.T) {
 	s := newStore()
 	// create directory /foo
+	var eidx uint64 = 2
 	s.Create("/foo", true, "", false, Permanent)
 	// delete /foo with dir = true and recursive = false
 	// this should succeed, since the directory is empty
 	e, err := s.Delete("/foo", true, false)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "delete", "")
-	// check pervNode
+	// check prevNode
 	assert.NotNil(t, e.PrevNode, "")
 	assert.Equal(t, e.PrevNode.Key, "/foo", "")
 	assert.Equal(t, e.PrevNode.Dir, true, "")
@@ -404,9 +439,11 @@ func TestRootRdOnly(t *testing.T) {
 
 func TestStoreCompareAndDeletePrevValue(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, err := s.CompareAndDelete("/foo", "bar", 0)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndDelete", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 
@@ -420,6 +457,7 @@ func TestStoreCompareAndDeletePrevValue(t *testing.T) {
 
 func TestStoreCompareAndDeletePrevValueFailsIfNotMatch(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, _err := s.CompareAndDelete("/foo", "baz", 0)
 	err := _err.(*etcdErr.Error)
@@ -427,14 +465,17 @@ func TestStoreCompareAndDeletePrevValueFailsIfNotMatch(t *testing.T) {
 	assert.Equal(t, err.Message, "Compare failed", "")
 	assert.Nil(t, e, "")
 	e, _ = s.Get("/foo", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 }
 
 func TestStoreCompareAndDeletePrevIndex(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, err := s.CompareAndDelete("/foo", "", 1)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndDelete", "")
 	// check pervNode
 	assert.NotNil(t, e.PrevNode, "")
@@ -446,6 +487,7 @@ func TestStoreCompareAndDeletePrevIndex(t *testing.T) {
 
 func TestStoreCompareAndDeletePrevIndexFailsIfNotMatch(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, _err := s.CompareAndDelete("/foo", "", 100)
 	assert.NotNil(t, _err, "")
@@ -454,6 +496,7 @@ func TestStoreCompareAndDeletePrevIndexFailsIfNotMatch(t *testing.T) {
 	assert.Equal(t, err.Message, "Compare failed", "")
 	assert.Nil(t, e, "")
 	e, _ = s.Get("/foo", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 }
 
@@ -470,9 +513,11 @@ func TestStoreCompareAndDeleteDiretoryFail(t *testing.T) {
 // Ensure that the store can conditionally update a key if it has a previous value.
 func TestStoreCompareAndSwapPrevValue(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, *e.Node.Value, "baz", "")
 	// check pervNode
@@ -489,6 +534,7 @@ func TestStoreCompareAndSwapPrevValue(t *testing.T) {
 // Ensure that the store cannot conditionally update a key if it has the wrong previous value.
 func TestStoreCompareAndSwapPrevValueFailsIfNotMatch(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, _err := s.CompareAndSwap("/foo", "wrong_value", 0, "baz", Permanent)
 	err := _err.(*etcdErr.Error)
@@ -497,17 +543,20 @@ func TestStoreCompareAndSwapPrevValueFailsIfNotMatch(t *testing.T) {
 	assert.Nil(t, e, "")
 	e, _ = s.Get("/foo", false, false)
 	assert.Equal(t, *e.Node.Value, "bar", "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 }
 
 // Ensure that the store can conditionally update a key if it has a previous index.
 func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, *e.Node.Value, "baz", "")
-	// check pervNode
+	// check prevNode
 	assert.NotNil(t, e.PrevNode, "")
 	assert.Equal(t, e.PrevNode.Key, "/foo", "")
 	assert.Equal(t, *e.PrevNode.Value, "bar", "")
@@ -516,11 +565,13 @@ func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
 
 	e, _ = s.Get("/foo", false, false)
 	assert.Equal(t, *e.Node.Value, "baz", "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 }
 
 // Ensure that the store cannot conditionally update a key if it has the wrong previous index.
 func TestStoreCompareAndSwapPrevIndexFailsIfNotMatch(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	s.Create("/foo", false, "bar", false, Permanent)
 	e, _err := s.CompareAndSwap("/foo", "", 100, "baz", Permanent)
 	err := _err.(*etcdErr.Error)
@@ -528,16 +579,19 @@ func TestStoreCompareAndSwapPrevIndexFailsIfNotMatch(t *testing.T) {
 	assert.Equal(t, err.Message, "Compare failed", "")
 	assert.Nil(t, e, "")
 	e, _ = s.Get("/foo", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 }
 
 // Ensure that the store can watch for key creation.
 func TestStoreWatchCreate(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	w, _ := s.Watch("/foo", false, false, 0)
 	c := w.EventChan()
 	s.Create("/foo", false, "bar", false, Permanent)
 	e := nbselect(c)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	e = nbselect(c)
@@ -547,9 +601,11 @@ func TestStoreWatchCreate(t *testing.T) {
 // Ensure that the store can watch for recursive key creation.
 func TestStoreWatchRecursiveCreate(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	w, _ := s.Watch("/foo", true, false, 0)
 	s.Create("/foo/bar", false, "baz", false, Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo/bar", "")
 }
@@ -557,10 +613,12 @@ func TestStoreWatchRecursiveCreate(t *testing.T) {
 // Ensure that the store can watch for key updates.
 func TestStoreWatchUpdate(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	w, _ := s.Watch("/foo", false, false, 0)
 	s.Update("/foo", "baz", Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 }
@@ -568,10 +626,12 @@ func TestStoreWatchUpdate(t *testing.T) {
 // Ensure that the store can watch for recursive key updates.
 func TestStoreWatchRecursiveUpdate(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo/bar", false, "baz", false, Permanent)
 	w, _ := s.Watch("/foo", true, false, 0)
 	s.Update("/foo/bar", "baz", Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo/bar", "")
 }
@@ -579,10 +639,12 @@ func TestStoreWatchRecursiveUpdate(t *testing.T) {
 // Ensure that the store can watch for key deletions.
 func TestStoreWatchDelete(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	w, _ := s.Watch("/foo", false, false, 0)
 	s.Delete("/foo", false, false)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "delete", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 }
@@ -590,10 +652,12 @@ func TestStoreWatchDelete(t *testing.T) {
 // Ensure that the store can watch for recursive key deletions.
 func TestStoreWatchRecursiveDelete(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo/bar", false, "baz", false, Permanent)
 	w, _ := s.Watch("/foo", true, false, 0)
 	s.Delete("/foo/bar", false, false)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "delete", "")
 	assert.Equal(t, e.Node.Key, "/foo/bar", "")
 }
@@ -601,10 +665,12 @@ func TestStoreWatchRecursiveDelete(t *testing.T) {
 // Ensure that the store can watch for CAS updates.
 func TestStoreWatchCompareAndSwap(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo", false, "bar", false, Permanent)
 	w, _ := s.Watch("/foo", false, false, 0)
 	s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 }
@@ -612,10 +678,12 @@ func TestStoreWatchCompareAndSwap(t *testing.T) {
 // Ensure that the store can watch for recursive CAS updates.
 func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/foo/bar", false, "baz", false, Permanent)
 	w, _ := s.Watch("/foo", true, false, 0)
 	s.CompareAndSwap("/foo/bar", "baz", 0, "bat", Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, e.Node.Key, "/foo/bar", "")
 }
@@ -630,6 +698,7 @@ func TestStoreWatchExpire(t *testing.T) {
 	}()
 	go mockSyncService(s.DeleteExpiredKeys, stopChan)
 
+	var eidx uint64 = 3
 	s.Create("/foo", false, "bar", false, time.Now().Add(500*time.Millisecond))
 	s.Create("/foofoo", false, "barbarbar", false, time.Now().Add(500*time.Millisecond))
 
@@ -639,10 +708,13 @@ func TestStoreWatchExpire(t *testing.T) {
 	assert.Nil(t, e, "")
 	time.Sleep(600 * time.Millisecond)
 	e = nbselect(c)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "expire", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	w, _ = s.Watch("/", true, false, 4)
 	e = nbselect(w.EventChan())
+	eidx = 4
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "expire", "")
 	assert.Equal(t, e.Node.Key, "/foofoo", "")
 }
@@ -650,18 +722,22 @@ func TestStoreWatchExpire(t *testing.T) {
 // Ensure that the store can watch in streaming mode.
 func TestStoreWatchStream(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	w, _ := s.Watch("/foo", false, true, 0)
 	// first modification
 	s.Create("/foo", false, "bar", false, Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 	e = nbselect(w.EventChan())
 	assert.Nil(t, e, "")
 	// second modification
+	eidx = 2
 	s.Update("/foo", "baz", Permanent)
 	e = nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, *e.Node.Value, "baz", "")
@@ -672,6 +748,7 @@ func TestStoreWatchStream(t *testing.T) {
 // Ensure that the store can recover from a previously saved state.
 func TestStoreRecover(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 3
 	s.Create("/foo", true, "", false, Permanent)
 	s.Create("/foo/x", false, "bar", false, Permanent)
 	s.Create("/foo/y", false, "baz", false, Permanent)
@@ -681,10 +758,12 @@ func TestStoreRecover(t *testing.T) {
 	s2.Recovery(b)
 
 	e, err := s.Get("/foo/x", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Nil(t, err, "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 
 	e, err = s.Get("/foo/y", false, false)
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Nil(t, err, "")
 	assert.Equal(t, *e.Node.Value, "baz", "")
 }
@@ -699,6 +778,7 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
 	}()
 	go mockSyncService(s.DeleteExpiredKeys, c)
 
+	var eidx uint64 = 4
 	s.Create("/foo", true, "", false, Permanent)
 	s.Create("/foo/x", false, "bar", false, Permanent)
 	s.Create("/foo/y", false, "baz", false, time.Now().Add(5*time.Millisecond))
@@ -720,6 +800,7 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
 
 	e, err := s.Get("/foo/x", false, false)
 	assert.Nil(t, err, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, *e.Node.Value, "bar", "")
 
 	e, err = s.Get("/foo/y", false, false)
@@ -730,9 +811,11 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
 // Ensure that the store can watch for hidden keys as long as it's an exact path match.
 func TestStoreWatchCreateWithHiddenKey(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	w, _ := s.Watch("/_foo", false, false, 0)
 	s.Create("/_foo", false, "bar", false, Permanent)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/_foo", "")
 	e = nbselect(w.EventChan())
@@ -781,10 +864,12 @@ func TestStoreWatchRecursiveUpdateWithHiddenKey(t *testing.T) {
 // Ensure that the store can watch for key deletions.
 func TestStoreWatchDeleteWithHiddenKey(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 2
 	s.Create("/_foo", false, "bar", false, Permanent)
 	w, _ := s.Watch("/_foo", false, false, 0)
 	s.Delete("/_foo", false, false)
 	e := nbselect(w.EventChan())
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "delete", "")
 	assert.Equal(t, e.Node.Key, "/_foo", "")
 	e = nbselect(w.EventChan())
@@ -830,11 +915,13 @@ func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
 // Ensure that the store does see hidden key creates if watching deeper than a hidden key in recursive mode.
 func TestStoreWatchRecursiveCreateDeeperThanHiddenKey(t *testing.T) {
 	s := newStore()
+	var eidx uint64 = 1
 	w, _ := s.Watch("/_foo/bar", true, false, 0)
 	s.Create("/_foo/bar/baz", false, "baz", false, Permanent)
 
 	e := nbselect(w.EventChan())
 	assert.NotNil(t, e, "")
+	assert.Equal(t, e.EtcdIndex, eidx, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/_foo/bar/baz", "")
 }