Skip to content

Commit

Permalink
cacher test: fix leftover v2 test server
Browse files Browse the repository at this point in the history
  • Loading branch information
hongchaodeng committed Nov 14, 2016
1 parent 454f60c commit 1972270
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions pkg/storage/cacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/storage/etcd3"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
Expand All @@ -45,15 +46,15 @@ import (
)

func newEtcdTestStorage(t *testing.T, codec runtime.Codec, prefix string) (*etcdtesting.EtcdTestServer, storage.Interface) {
server := etcdtesting.NewEtcdTestClientServer(t)
storage := etcdstorage.NewEtcdStorage(server.Client, codec, prefix, false, etcdtest.DeserializationCacheSize)
server, _ := etcdtesting.NewUnsecuredEtcd3TestClientServer(t)
storage := etcd3.New(server.V3Client, codec, prefix)
return server, storage
}

func newTestCacher(s storage.Interface) *storage.Cacher {
func newTestCacher(s storage.Interface, cap int) *storage.Cacher {
prefix := "pods"
config := storage.CacherConfig{
CacheCapacity: 10,
CacheCapacity: cap,
Storage: s,
Versioner: etcdstorage.APIObjectVersioner{},
Type: &api.Pod{},
Expand Down Expand Up @@ -96,7 +97,7 @@ func updatePod(t *testing.T, s storage.Interface, obj, old *api.Pod) *api.Pod {
func TestList(t *testing.T) {
server, etcdStorage := newEtcdTestStorage(t, testapi.Default.Codec(), etcdtest.PathPrefix())
defer server.Terminate(t)
cacher := newTestCacher(etcdStorage)
cacher := newTestCacher(etcdStorage, 10)
defer cacher.Stop()

podFoo := makeTestPod("foo")
Expand Down Expand Up @@ -210,7 +211,7 @@ func TestWatch(t *testing.T) {
// Inject one list error to make sure we test the relist case.
etcdStorage = &injectListError{errors: 1, Interface: etcdStorage}
defer server.Terminate(t)
cacher := newTestCacher(etcdStorage)
cacher := newTestCacher(etcdStorage, 3) // small capacity to trigger "too old version" error
defer cacher.Stop()

podFoo := makeTestPod("foo")
Expand Down Expand Up @@ -285,7 +286,7 @@ func TestWatch(t *testing.T) {
func TestWatcherTimeout(t *testing.T) {
server, etcdStorage := newEtcdTestStorage(t, testapi.Default.Codec(), etcdtest.PathPrefix())
defer server.Terminate(t)
cacher := newTestCacher(etcdStorage)
cacher := newTestCacher(etcdStorage, 10)
defer cacher.Stop()

// initialVersion is used to initate the watcher at the beginning of the world,
Expand Down Expand Up @@ -320,7 +321,7 @@ func TestWatcherTimeout(t *testing.T) {
func TestFiltering(t *testing.T) {
server, etcdStorage := newEtcdTestStorage(t, testapi.Default.Codec(), etcdtest.PathPrefix())
defer server.Terminate(t)
cacher := newTestCacher(etcdStorage)
cacher := newTestCacher(etcdStorage, 10)
defer cacher.Stop()

// Ensure that the cacher is initialized, before creating any pods,
Expand Down Expand Up @@ -382,7 +383,7 @@ func TestFiltering(t *testing.T) {
func TestStartingResourceVersion(t *testing.T) {
server, etcdStorage := newEtcdTestStorage(t, testapi.Default.Codec(), etcdtest.PathPrefix())
defer server.Terminate(t)
cacher := newTestCacher(etcdStorage)
cacher := newTestCacher(etcdStorage, 10)
defer cacher.Stop()

// add 1 object
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/etcd/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type EtcdTestServer struct {

// The following are lumped etcd3 test server params
v3Cluster *integration.ClusterV3
v3Client *clientv3.Client
V3Client *clientv3.Client
}

// newLocalListener opens a port localhost using any port
Expand Down Expand Up @@ -314,11 +314,11 @@ func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storageb
server := &EtcdTestServer{
v3Cluster: integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}),
}
server.v3Client = server.v3Cluster.RandClient()
server.V3Client = server.v3Cluster.RandClient()
config := &storagebackend.Config{
Type: "etcd3",
Prefix: etcdtest.PathPrefix(),
ServerList: server.v3Client.Endpoints(),
ServerList: server.V3Client.Endpoints(),
DeserializationCacheSize: etcdtest.DeserializationCacheSize,
}
return server, config
Expand Down

0 comments on commit 1972270

Please sign in to comment.