Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cacher_test flakes #19213

Merged
merged 1 commit into from
Dec 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions pkg/storage/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,6 @@ func (c *Cacher) LastSyncResourceVersion() (uint64, error) {
return strconv.ParseUint(resourceVersion, 10, 64)
}

// For debugging #18794 only.
func (c *Cacher) GetAllCachedEvents() ([]watchCacheEvent, error) {
return c.watchCache.getAllCachedEvents()
}

// cacherListerWatcher opaques storage.Interface to expose cache.ListerWatcher.
type cacherListerWatcher struct {
storage Interface
Expand Down
18 changes: 8 additions & 10 deletions pkg/storage/cacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/watch"

"github.com/golang/glog"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -271,6 +270,14 @@ func TestFiltering(t *testing.T) {
cacher := newTestCacher(etcdStorage)
defer cacher.Stop()

// Ensure that the cacher is initialized, before creating any pods,
// so that we are sure that all events will be present in cacher.
syncWatcher, err := cacher.Watch(context.TODO(), "pods/ns/foo", "0", storage.Everything)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
syncWatcher.Stop()

podFoo := makeTestPod("foo")
podFoo.Labels = map[string]string{"filter": "foo"}
podFooFiltered := makeTestPod("foo")
Expand Down Expand Up @@ -300,15 +307,6 @@ func TestFiltering(t *testing.T) {
}
watcher, err := cacher.Watch(context.TODO(), "pods/ns/foo", fooCreated.ResourceVersion, filter)
if err != nil {
// For debugging #18794 only.
events, err := cacher.GetAllCachedEvents()
if err != nil {
glog.Error("Unexpected error: %v", err)
} else {
for _, event := range events {
glog.Errorf("cached event: %s %#v", event.Type, event.Object)
}
}
t.Fatalf("Unexpected error: %v", err)
}
defer watcher.Stop()
Expand Down
10 changes: 0 additions & 10 deletions pkg/storage/watch_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,3 @@ func (w *watchCache) GetAllEventsSince(resourceVersion uint64) ([]watchCacheEven
defer w.RUnlock()
return w.GetAllEventsSinceThreadUnsafe(resourceVersion)
}

// For debugging #18794 only.
func (w *watchCache) getAllCachedEvents() ([]watchCacheEvent, error) {
w.RLock()
defer w.RUnlock()
if w.startIndex == w.endIndex {
return make([]watchCacheEvent, 0), nil
}
return w.GetAllEventsSinceThreadUnsafe(w.cache[w.startIndex%w.capacity].resourceVersion)
}