mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
test(store): group together all store tests that deal with hidden keys
This commit is contained in:
parent
823fdfab12
commit
641edd4e6e
@ -499,18 +499,6 @@ func TestStoreWatchCreate(t *testing.T) {
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// 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()
|
||||
w, _ := s.Watch("/_foo", false, false, 0)
|
||||
s.Create("/_foo", false, "bar", false, Permanent)
|
||||
e := nbselect(w.EventChan)
|
||||
assert.Equal(t, e.Action, "create", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for recursive key creation.
|
||||
func TestStoreWatchRecursiveCreate(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -521,22 +509,6 @@ func TestStoreWatchRecursiveCreate(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foo/bar", "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key creates without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveCreateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
w, _ := s.Watch("/foo", true, false, 0)
|
||||
s.Create("/foo/_bar", false, "baz", false, Permanent)
|
||||
e := nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
w, _ = s.Watch("/foo", true, false, 0)
|
||||
s.Create("/foo/_baz", true, "", false, Permanent)
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
s.Create("/foo/_baz/quux", false, "quux", false, Permanent)
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for key updates.
|
||||
func TestStoreWatchUpdate(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -548,19 +520,6 @@ func TestStoreWatchUpdate(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foo", "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key updates.
|
||||
func TestStoreWatchUpdateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Action, "update", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for recursive key updates.
|
||||
func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -572,16 +531,6 @@ func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foo/bar", "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key updates without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveUpdateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for key deletions.
|
||||
func TestStoreWatchDelete(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -593,19 +542,6 @@ func TestStoreWatchDelete(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foo", "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for key deletions.
|
||||
func TestStoreWatchDeleteWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Action, "delete", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for recursive key deletions.
|
||||
func TestStoreWatchRecursiveDelete(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -617,16 +553,6 @@ func TestStoreWatchRecursiveDelete(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foo/bar", "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key deletes without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveDeleteWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for CAS updates.
|
||||
func TestStoreWatchCompareAndSwap(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -676,32 +602,6 @@ func TestStoreWatchExpire(t *testing.T) {
|
||||
assert.Equal(t, e.Node.Key, "/foofoo", "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see expirations of hidden keys.
|
||||
func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
|
||||
stopChan := make(chan bool)
|
||||
defer func() {
|
||||
stopChan <- true
|
||||
}()
|
||||
go mockSyncService(s.DeleteExpiredKeys, stopChan)
|
||||
|
||||
s.Create("/_foo", false, "bar", false, time.Now().Add(500*time.Millisecond))
|
||||
s.Create("/foofoo", false, "barbarbar", false, time.Now().Add(1000*time.Millisecond))
|
||||
|
||||
w, _ := s.Watch("/", true, false, 0)
|
||||
c := w.EventChan
|
||||
e := nbselect(c)
|
||||
assert.Nil(t, e, "")
|
||||
time.Sleep(600 * time.Millisecond)
|
||||
e = nbselect(c)
|
||||
assert.Nil(t, e, "")
|
||||
time.Sleep(600 * time.Millisecond)
|
||||
e = nbselect(c)
|
||||
assert.Equal(t, e.Action, "expire", "")
|
||||
assert.Equal(t, e.Node.Key, "/foofoo", "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch in streaming mode.
|
||||
func TestStoreWatchStream(t *testing.T) {
|
||||
s := newStore()
|
||||
@ -782,6 +682,106 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// 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()
|
||||
w, _ := s.Watch("/_foo", false, false, 0)
|
||||
s.Create("/_foo", false, "bar", false, Permanent)
|
||||
e := nbselect(w.EventChan)
|
||||
assert.Equal(t, e.Action, "create", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key creates without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveCreateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
w, _ := s.Watch("/foo", true, false, 0)
|
||||
s.Create("/foo/_bar", false, "baz", false, Permanent)
|
||||
e := nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
w, _ = s.Watch("/foo", true, false, 0)
|
||||
s.Create("/foo/_baz", true, "", false, Permanent)
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
s.Create("/foo/_baz/quux", false, "quux", false, Permanent)
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key updates.
|
||||
func TestStoreWatchUpdateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Action, "update", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key updates without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveUpdateWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store can watch for key deletions.
|
||||
func TestStoreWatchDeleteWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Action, "delete", "")
|
||||
assert.Equal(t, e.Node.Key, "/_foo", "")
|
||||
e = nbselect(w.EventChan)
|
||||
assert.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see hidden key deletes without an exact path match in recursive mode.
|
||||
func TestStoreWatchRecursiveDeleteWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
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.Nil(t, e, "")
|
||||
}
|
||||
|
||||
// Ensure that the store doesn't see expirations of hidden keys.
|
||||
func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
|
||||
s := newStore()
|
||||
|
||||
stopChan := make(chan bool)
|
||||
defer func() {
|
||||
stopChan <- true
|
||||
}()
|
||||
go mockSyncService(s.DeleteExpiredKeys, stopChan)
|
||||
|
||||
s.Create("/_foo", false, "bar", false, time.Now().Add(500*time.Millisecond))
|
||||
s.Create("/foofoo", false, "barbarbar", false, time.Now().Add(1000*time.Millisecond))
|
||||
|
||||
w, _ := s.Watch("/", true, false, 0)
|
||||
c := w.EventChan
|
||||
e := nbselect(c)
|
||||
assert.Nil(t, e, "")
|
||||
time.Sleep(600 * time.Millisecond)
|
||||
e = nbselect(c)
|
||||
assert.Nil(t, e, "")
|
||||
time.Sleep(600 * time.Millisecond)
|
||||
e = nbselect(c)
|
||||
assert.Equal(t, e.Action, "expire", "")
|
||||
assert.Equal(t, e.Node.Key, "/foofoo", "")
|
||||
}
|
||||
|
||||
// Performs a non-blocking select on an event channel.
|
||||
func nbselect(c <-chan *Event) *Event {
|
||||
select {
|
||||
|
Loading…
x
Reference in New Issue
Block a user