mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
storage: add tests for unsafeAddWatching
This adds map operation tests for unsafeAddWatching, which could have been failed without https://github.com/coreos/etcd/pull/3939. It tests if unsafeAddWatching is correctly updating synced map.
This commit is contained in:
parent
14210cf8a7
commit
ff2e8b55ae
@ -69,29 +69,30 @@ func TestUnsafeAddWatching(t *testing.T) {
|
|||||||
testValue := []byte("bar")
|
testValue := []byte("bar")
|
||||||
s.Put(testKey, testValue)
|
s.Put(testKey, testValue)
|
||||||
|
|
||||||
wa := &watching{
|
size := 10
|
||||||
|
ws := make([]*watching, size)
|
||||||
|
for i := 0; i < size; i++ {
|
||||||
|
ws[i] = &watching{
|
||||||
key: testKey,
|
key: testKey,
|
||||||
prefix: true,
|
prefix: true,
|
||||||
cur: 0,
|
cur: 0,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// to test if unsafeAddWatching is correctly updating
|
||||||
|
// synced map when adding new watching.
|
||||||
|
for i, wa := range ws {
|
||||||
if err := unsafeAddWatching(&s.synced, string(testKey), wa); err != nil {
|
if err := unsafeAddWatching(&s.synced, string(testKey), wa); err != nil {
|
||||||
t.Error(err)
|
t.Errorf("#%d: error = %v, want nil", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := s.synced[string(testKey)]; !ok {
|
if v, ok := s.synced[string(testKey)]; !ok {
|
||||||
// the key must have had entry in synced
|
t.Errorf("#%d: ok = %v, want ok true", i, ok)
|
||||||
t.Errorf("existence = %v, want true", ok)
|
|
||||||
} else {
|
} else {
|
||||||
if len(v) != 1 {
|
if len(v) != i+1 {
|
||||||
// the key must have ONE entry in its watching map
|
t.Errorf("#%d: len(v) = %d, want %d", i, len(v), i+1)
|
||||||
t.Errorf("len(v) = %d, want 1", len(v))
|
}
|
||||||
|
if _, ok := v[wa]; !ok {
|
||||||
|
t.Errorf("#%d: ok = %v, want ok true", i, ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := unsafeAddWatching(&s.synced, string(testKey), wa); err == nil {
|
|
||||||
// unsafeAddWatching should have returned error
|
|
||||||
// when putting the same watch twice"
|
|
||||||
t.Error(`error = nil, want "put the same watch twice"`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user