mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7188 from jl2005/dir-expire
store: set e.Node.Dir attribute, when node expired
This commit is contained in:
commit
d03d7f0c0d
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user