mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
store: set Dir attribute, when node expired
This commit is contained in:
parent
d62ce55584
commit
99639186cd
@ -682,6 +682,9 @@ func (s *store) DeleteExpiredKeys(cutoff time.Time) {
|
|||||||
e := newEvent(Expire, node.Path, s.CurrentIndex, node.CreatedIndex)
|
e := newEvent(Expire, node.Path, s.CurrentIndex, node.CreatedIndex)
|
||||||
e.EtcdIndex = s.CurrentIndex
|
e.EtcdIndex = s.CurrentIndex
|
||||||
e.PrevNode = node.Repr(false, false, s.clock)
|
e.PrevNode = node.Repr(false, false, s.clock)
|
||||||
|
if node.IsDir() {
|
||||||
|
e.Node.Dir = true
|
||||||
|
}
|
||||||
|
|
||||||
callback := func(path string) { // notify function
|
callback := func(path string) { // notify function
|
||||||
// notify the watchers with deleted set true
|
// notify the watchers with deleted set true
|
||||||
|
@ -736,9 +736,10 @@ func TestStoreWatchExpire(t *testing.T) {
|
|||||||
fc := newFakeClock()
|
fc := newFakeClock()
|
||||||
s.clock = fc
|
s.clock = fc
|
||||||
|
|
||||||
var eidx uint64 = 2
|
var eidx uint64 = 3
|
||||||
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
|
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(500 * 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)
|
w, _ := s.Watch("/", true, false, 0)
|
||||||
assert.Equal(t, w.StartIndex(), eidx, "")
|
assert.Equal(t, w.StartIndex(), eidx, "")
|
||||||
@ -747,18 +748,24 @@ func TestStoreWatchExpire(t *testing.T) {
|
|||||||
assert.Nil(t, e, "")
|
assert.Nil(t, e, "")
|
||||||
fc.Advance(600 * time.Millisecond)
|
fc.Advance(600 * time.Millisecond)
|
||||||
s.DeleteExpiredKeys(fc.Now())
|
s.DeleteExpiredKeys(fc.Now())
|
||||||
eidx = 3
|
eidx = 4
|
||||||
e = nbselect(c)
|
e = nbselect(c)
|
||||||
assert.Equal(t, e.EtcdIndex, eidx, "")
|
assert.Equal(t, e.EtcdIndex, eidx, "")
|
||||||
assert.Equal(t, e.Action, "expire", "")
|
assert.Equal(t, e.Action, "expire", "")
|
||||||
assert.Equal(t, e.Node.Key, "/foo", "")
|
assert.Equal(t, e.Node.Key, "/foo", "")
|
||||||
w, _ = s.Watch("/", true, false, 4)
|
w, _ = s.Watch("/", true, false, 5)
|
||||||
eidx = 4
|
eidx = 6
|
||||||
assert.Equal(t, w.StartIndex(), eidx, "")
|
assert.Equal(t, w.StartIndex(), eidx, "")
|
||||||
e = nbselect(w.EventChan())
|
e = nbselect(w.EventChan())
|
||||||
assert.Equal(t, e.EtcdIndex, eidx, "")
|
assert.Equal(t, e.EtcdIndex, eidx, "")
|
||||||
assert.Equal(t, e.Action, "expire", "")
|
assert.Equal(t, e.Action, "expire", "")
|
||||||
assert.Equal(t, e.Node.Key, "/foofoo", "")
|
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.
|
// Ensure that the store can watch for key expiration when refreshing.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user