From 99639186cd41eebd3f905935df586a9094a2bfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=84=A6=E9=BE=99?= Date: Thu, 19 Jan 2017 18:00:56 +0800 Subject: [PATCH] store: set Dir attribute, when node expired --- store/store.go | 3 +++ store/store_test.go | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/store/store.go b/store/store.go index 6c19ad4c9..edf7f2194 100644 --- a/store/store.go +++ b/store/store.go @@ -682,6 +682,9 @@ func (s *store) DeleteExpiredKeys(cutoff time.Time) { e := newEvent(Expire, node.Path, s.CurrentIndex, node.CreatedIndex) e.EtcdIndex = s.CurrentIndex e.PrevNode = node.Repr(false, false, s.clock) + if node.IsDir() { + e.Node.Dir = true + } callback := func(path string) { // notify function // notify the watchers with deleted set true diff --git a/store/store_test.go b/store/store_test.go index 6c21c4ad3..006a48870 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -736,9 +736,10 @@ func TestStoreWatchExpire(t *testing.T) { fc := newFakeClock() s.clock = fc - var eidx uint64 = 2 - s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)}) - s.Create("/foofoo", false, "barbarbar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)}) + var eidx uint64 = 3 + s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(400 * time.Millisecond)}) + s.Create("/foofoo", false, "barbarbar", false, TTLOptionSet{ExpireTime: fc.Now().Add(450 * time.Millisecond)}) + s.Create("/foodir", true, "", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)}) w, _ := s.Watch("/", true, false, 0) assert.Equal(t, w.StartIndex(), eidx, "") @@ -747,18 +748,24 @@ func TestStoreWatchExpire(t *testing.T) { assert.Nil(t, e, "") fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) - eidx = 3 + eidx = 4 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) - eidx = 4 + w, _ = s.Watch("/", true, false, 5) + eidx = 6 assert.Equal(t, w.StartIndex(), eidx, "") e = nbselect(w.EventChan()) assert.Equal(t, e.EtcdIndex, eidx, "") assert.Equal(t, e.Action, "expire", "") assert.Equal(t, e.Node.Key, "/foofoo", "") + w, _ = s.Watch("/", true, false, 6) + e = nbselect(w.EventChan()) + assert.Equal(t, e.EtcdIndex, eidx, "") + assert.Equal(t, e.Action, "expire", "") + assert.Equal(t, e.Node.Key, "/foodir", "") + assert.Equal(t, e.Node.Dir, true, "") } // Ensure that the store can watch for key expiration when refreshing.